provide cli function stop, restart and reload for hbd

Thought for 1s
This commit is contained in:
Andreas Wrede
2026-04-12 12:06:07 -04:00
parent 3a030548c0
commit 24b0e362fb
3 changed files with 133 additions and 0 deletions
+16
View File
@@ -475,6 +475,16 @@ def run(config, config_path=None):
notify_mod.initlog(logfile=config.get("logfile", "messages.log"))
users_mod.load_users(config)
# Write pidfile
pidfile = config.get("pidfile", "")
if pidfile:
try:
with open(pidfile, "w") as f:
f.write(str(os.getpid()))
except Exception as e:
logger.warning("Failed to write pidfile %s: %s", pidfile, e)
eventlog(None, "INFO", f"hbd version {__version__} starting up")
if config_path:
@@ -497,6 +507,12 @@ def run(config, config_path=None):
logger.info("hbd shutdown complete")
eventlog(None, "INFO", f"hbd version {__version__} shutdown")
notify_mod.closelog()
# Remove pidfile
if pidfile:
try:
os.unlink(pidfile)
except Exception:
pass
# Explicitly close the loop
try:
# Cancel all remaining tasks