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 <noreply@anthropic.com>
This commit is contained in:
+6
-3
@@ -486,7 +486,8 @@ async def cleanup(connections: List[AsyncConnection]):
|
|||||||
logger.info("Cleaning up connections")
|
logger.info("Cleaning up connections")
|
||||||
|
|
||||||
target = next((c for c in connections if c.transport), connections[0] if connections else None)
|
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:
|
try:
|
||||||
await target.sendto({"shutdown": 1, "acks": target.ackcount})
|
await target.sendto({"shutdown": 1, "acks": target.ackcount})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -564,7 +565,6 @@ async def async_main(args, config):
|
|||||||
boot_msg = {}
|
boot_msg = {}
|
||||||
if args.boot:
|
if args.boot:
|
||||||
boot_msg["boot"] = 1
|
boot_msg["boot"] = 1
|
||||||
args.boot = False # Clear boot flag so we don't send it again in main loop
|
|
||||||
send_shutdown = True
|
send_shutdown = True
|
||||||
if args.message:
|
if args.message:
|
||||||
boot_msg["service"] = "service"
|
boot_msg["service"] = "service"
|
||||||
@@ -793,7 +793,10 @@ def main(argv=None):
|
|||||||
# Handle restart
|
# Handle restart
|
||||||
if dorestart:
|
if dorestart:
|
||||||
logging.info("Restarting...")
|
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)
|
sys.exit(exit_code)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user