From 7afc06a32903a50ffbaed930f360bdfc2fba5a6f Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Fri, 10 Jul 2026 15:11:30 -0400 Subject: [PATCH] fix: journal startup/shutdown lifecycle events (fired outside journal lifetime) Co-Authored-By: Claude Fable 5 --- hbd/server/main.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/hbd/server/main.py b/hbd/server/main.py index 0398f17..2a2a10e 100644 --- a/hbd/server/main.py +++ b/hbd/server/main.py @@ -172,6 +172,8 @@ async def _run_async(config, config_path=None): # One-time seed on upgrade: only writes when the journal file is empty await events_journal.backfill(data.msgs) + notify_mod.eventlog(None, "INFO", f"hbd version {__version__} starting up") + # Initialize threshold checker threshold_checker = threshold_mod.ThresholdChecker( config=config, @@ -386,6 +388,20 @@ async def _run_async(config, config_path=None): except Exception as e: logger.warning("Error closing message journal: %s", e) + # Journal the shutdown event now; run()'s shutdown eventlog fires after this journal closes + try: + await events_journal.log_event( + { + "ts": time.time(), + "host": None, + "level": "INFO", + "service": None, + "message": f"hbd version {__version__} shutdown", + } + ) + except Exception as e: + logger.debug("Could not journal shutdown event: %s", e) + # Close events journal try: await events_journal.close() @@ -500,8 +516,6 @@ def run(config, config_path=None): 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: logger.info(f"Config file: {config_path} (reload with SIGHUP)") else: