From 960822918ad21b5c28fb2d9ca4b4e96bb988dc4a Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Sat, 27 Jun 2026 15:46:09 -0400 Subject: [PATCH] fix: don't re-announce boot/shutdown on SIGHUP restart Setting args.boot = False after sending the boot message was dead code: the SIGHUP restart re-execs via os.execv(sys.argv[0], sys.argv) with the original argv, so the re-launched process re-parsed -b and announced a boot again. The exiting process also sent a spurious shutdown (send_shutdown armed by -b), so each config reload looked like a host reboot to the server. Strip -b/--boot from the argv passed to execv, and skip the shutdown message in cleanup() when dorestart is set. A real SIGTERM/SIGINT shutdown still sends shutdown as before. Co-Authored-By: Claude Opus 4.8 --- hbd/client/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hbd/client/main.py b/hbd/client/main.py index 6885da1..641bcf3 100644 --- a/hbd/client/main.py +++ b/hbd/client/main.py @@ -486,7 +486,8 @@ async def cleanup(connections: List[AsyncConnection]): logger.info("Cleaning up connections") target = next((c for c in connections if c.transport), connections[0] if connections else None) - if target and send_shutdown: + # A SIGHUP restart is not a host shutdown, so don't announce one. + if target and send_shutdown and not dorestart: try: await target.sendto({"shutdown": 1, "acks": target.ackcount}) except Exception as e: @@ -564,7 +565,6 @@ async def async_main(args, config): boot_msg = {} if args.boot: boot_msg["boot"] = 1 - args.boot = False # Clear boot flag so we don't send it again in main loop send_shutdown = True if args.message: boot_msg["service"] = "service" @@ -793,7 +793,10 @@ def main(argv=None): # Handle restart if dorestart: logging.info("Restarting...") - os.execv(sys.argv[0], sys.argv) + # Drop -b/--boot so the re-exec'd process doesn't re-announce a boot; + # a SIGHUP restart is not a host reboot. + restart_argv = [sys.argv[0]] + [a for a in sys.argv[1:] if a not in ("-b", "--boot")] + os.execv(restart_argv[0], restart_argv) sys.exit(exit_code)