MCPcopy Index your code
hub / github.com/AstrBotDevs/AstrBot / run

Function run

astrbot/cli/commands/cmd_run.py:39–74  ·  view source on GitHub ↗

Run AstrBot

(reload: bool, port: str | None, reset_password: bool)

Source from the content-addressed store, hash-verified

37)
38@click.command()
39def run(reload: bool, port: str | None, reset_password: bool) -> None:
40 """Run AstrBot"""
41 try:
42 os.environ["ASTRBOT_CLI"] = "1"
43 astrbot_root = get_astrbot_root()
44
45 if not check_astrbot_root(astrbot_root):
46 raise click.ClickException(
47 f"{astrbot_root} is not a valid AstrBot root directory. Use 'astrbot init' to initialize",
48 )
49
50 os.environ["ASTRBOT_ROOT"] = str(astrbot_root)
51 sys.path.insert(0, str(astrbot_root))
52
53 if port:
54 os.environ["DASHBOARD_PORT"] = port
55
56 if reload:
57 click.echo("Plugin auto-reload enabled")
58 os.environ["ASTRBOT_RELOAD"] = "1"
59
60 if reset_password:
61 os.environ[DASHBOARD_RESET_PASSWORD_ENV] = "1"
62
63 lock_file = astrbot_root / "astrbot.lock"
64 lock = FileLock(lock_file, timeout=5)
65 with lock.acquire():
66 asyncio.run(run_astrbot(astrbot_root))
67 except KeyboardInterrupt:
68 click.echo("AstrBot has been shut down.")
69 except Timeout:
70 raise click.ClickException(
71 "Cannot acquire lock file. Please check if another instance is running"
72 )
73 except Exception as e:
74 raise click.ClickException(f"Runtime error: {e}\n{traceback.format_exc()}")

Callers 1

callMethod · 0.50

Calls 6

check_astrbot_rootFunction · 0.85
run_astrbotFunction · 0.85
get_astrbot_rootFunction · 0.50
insertMethod · 0.45
acquireMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected