From 2bd3a9beb653c5660e3831cc0bf46c9a346931ae Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Sat, 2 May 2026 10:06:26 -0400 Subject: [PATCH] feat: restart on SIGHUP in hbc and hbc_mini Sets dorestart and triggers a clean shutdown; os.execv re-execs the process with the original arguments after cleanup. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- hbd/client/main.py | 7 +++++++ scripts/hbc_mini.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/hbd/client/main.py b/hbd/client/main.py index dd9ccce..ce05c62 100644 --- a/hbd/client/main.py +++ b/hbd/client/main.py @@ -524,6 +524,13 @@ async def async_main(args, config): loop = asyncio.get_event_loop() for sig in (signal.SIGTERM, signal.SIGINT): loop.add_signal_handler(sig, stop) + + def _sighup(): + global dorestart + dorestart = True + stop() + + loop.add_signal_handler(signal.SIGHUP, _sighup) # Start async tasks # Heartbeat senders (one per connection) diff --git a/scripts/hbc_mini.py b/scripts/hbc_mini.py index 25fef8b..735aad8 100755 --- a/scripts/hbc_mini.py +++ b/scripts/hbc_mini.py @@ -1066,6 +1066,13 @@ async def _async_main(args, cfg: Dict[str, Any]) -> int: for sig in (signal.SIGTERM, signal.SIGINT): loop.add_signal_handler(sig, _stop) + def _sighup(): + global _dorestart + _dorestart = True + _stop() + + loop.add_signal_handler(signal.SIGHUP, _sighup) + for conn in connections: _active_tasks.append(asyncio.create_task(_heartbeat_sender(conn, interval)))