aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/daemon.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/daemon.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/daemon.py65
1 files changed, 59 insertions, 6 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/daemon.py b/packages/meshbay-node/src/meshbay_node/daemon.py
index 37a2472..b932c16 100644
--- a/packages/meshbay-node/src/meshbay_node/daemon.py
+++ b/packages/meshbay-node/src/meshbay_node/daemon.py
@@ -1649,7 +1649,7 @@ def main() -> None:
choices=["init", "reset", "status", "gek-init",
"gek", "operator", "member", "group", "file",
"video", "denylist", "stun", "reload",
- "restart-daemon", "autostart",
+ "restart-daemon", "autostart", "service",
"calibrate-argon2"],
help="init: provision config + keystore | reset: erase all "
"node state | status: node state and keys "
@@ -1661,16 +1661,21 @@ def main() -> None:
"| stun list|add|remove|reset "
"| reload: re-read node.toml (hot; systemd or the "
"loopback API) | restart-daemon: restart the node "
- "(systemd unit, or the Windows autostart launcher) "
+ "(systemd unit, the Windows autostart launcher, or the "
+ "service task, whichever applies) "
"| autostart install|remove|start|stop|status "
- "(Windows: run meshbay-node at each sign-in) "
+ "(Windows: run meshbay-node at each sign-in, no admin) "
+ "| service install|remove|start|stop|status "
+ "(Windows: run at boot, before sign-in, needs admin "
+ "once to install) "
"| calibrate-argon2: benchmark")
parser.add_argument("subcommand", nargs="?",
help="'pair' for operator; list|invite|revoke|unpin for "
"member; list|add|remove for group; init|rotate for gek; "
"list|rm for file; rematch for video; show|clear for "
"denylist; list|add|remove|reset for stun; "
- "install|remove|start|stop|status for autostart")
+ "install|remove|start|stop|status for autostart and "
+ "for service")
parser.add_argument("target", nargs="?",
help="username for member invite|revoke|unpin; group name "
"for group add; file id for file rm; identifier for "
@@ -1845,8 +1850,9 @@ def main() -> None:
print("Could not unlink from hub (daemon not reachable).")
if sys.platform == "win32":
- from meshbay_node.platform import autostart_remove
+ from meshbay_node.platform import autostart_remove, service_remove
autostart_remove()
+ service_remove() # no-op, silently, if not elevated or not installed
else:
_sp.run(["systemctl", "--user", "disable", "--now", "meshbay-node"],
capture_output=True)
@@ -2107,7 +2113,14 @@ def main() -> None:
if args.command == "restart-daemon":
if sys.platform == "win32":
- from meshbay_node.platform import autostart_end, autostart_run
+ from meshbay_node.platform import (
+ autostart_end, autostart_run, service_end, service_run, service_status,
+ )
+ if service_status()["installed"]:
+ service_end()
+ service_run()
+ print("restarted the node (service task)")
+ return
autostart_end() # kill whatever is running now
try:
autostart_run()
@@ -2162,6 +2175,46 @@ def main() -> None:
sys.exit(1)
return
+ if args.command == "service":
+ from meshbay_node import platform as _plat
+ if sys.platform != "win32":
+ print("service mode is Windows-only — elsewhere use "
+ "'systemctl --user enable --now meshbay-node'.")
+ sys.exit(1)
+ sub = args.subcommand or "status"
+ if sub == "install":
+ try:
+ _plat.service_install()
+ except RuntimeError as e:
+ print(f"Could not install: {e}")
+ if "denied" in str(e).lower():
+ print("Run this from an elevated (Administrator) prompt.")
+ sys.exit(1)
+ print(f"Registered the {_plat.TASK_NAME!r} scheduled task — it starts "
+ "meshbay-node at boot, as this user, whether or not you have "
+ "signed in yet (no password stored).")
+ print("Start it now with: meshbay-node service start")
+ elif sub == "remove":
+ _plat.service_remove()
+ print(f"Removed the {_plat.TASK_NAME!r} scheduled task.")
+ elif sub == "start":
+ _plat.service_run()
+ print("started")
+ elif sub == "stop":
+ _plat.service_end()
+ print("stopped")
+ elif sub == "status":
+ st = _plat.service_status()
+ if st["installed"]:
+ print(f"service installed — {st['state'] or 'unknown state'}")
+ else:
+ print("service not installed — meshbay-node service install "
+ "(needs an elevated prompt)")
+ else:
+ print("service: install | remove | start | stop | status")
+ sys.exit(1)
+ return
+
if args.command == "denylist":
cfg = load_config(args.config or DEFAULT_CONFIG_PATH)
sub = args.subcommand or "show"