fix: journal startup/shutdown lifecycle events (fired outside journal lifetime)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-10 15:11:30 -04:00
co-authored by Claude Fable 5
parent a3f303e6ba
commit 7afc06a329
+16 -2
View File
@@ -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 # One-time seed on upgrade: only writes when the journal file is empty
await events_journal.backfill(data.msgs) await events_journal.backfill(data.msgs)
notify_mod.eventlog(None, "INFO", f"hbd version {__version__} starting up")
# Initialize threshold checker # Initialize threshold checker
threshold_checker = threshold_mod.ThresholdChecker( threshold_checker = threshold_mod.ThresholdChecker(
config=config, config=config,
@@ -386,6 +388,20 @@ async def _run_async(config, config_path=None):
except Exception as e: except Exception as e:
logger.warning("Error closing message journal: %s", 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 # Close events journal
try: try:
await events_journal.close() await events_journal.close()
@@ -500,8 +516,6 @@ def run(config, config_path=None):
except Exception as e: except Exception as e:
logger.warning("Failed to write pidfile %s: %s", pidfile, e) logger.warning("Failed to write pidfile %s: %s", pidfile, e)
eventlog(None, "INFO", f"hbd version {__version__} starting up")
if config_path: if config_path:
logger.info(f"Config file: {config_path} (reload with SIGHUP)") logger.info(f"Config file: {config_path} (reload with SIGHUP)")
else: else: