diff --git a/hbd/server/main.py b/hbd/server/main.py index 6c4e125..270b2d3 100644 --- a/hbd/server/main.py +++ b/hbd/server/main.py @@ -426,6 +426,13 @@ async def _run_async(config, config_path=None): except Exception as e: logger.warning("Error stopping DNS worker: %s", e) + # Save state (hosts + sessions) on clean shutdown + try: + save_state(config, hbdclass) + logger.info("State saved on shutdown") + except Exception as e: + logger.warning("Error saving state on shutdown: %s", e) + logger.info("All tasks cancelled") diff --git a/hbd/server/udp.py b/hbd/server/udp.py index 11cd7af..7d441bb 100644 --- a/hbd/server/udp.py +++ b/hbd/server/udp.py @@ -412,13 +412,16 @@ def handle_datagram(msg: dict, addr, transport, ctx: dict): if conn.getstate() != hbdcls.Connection.UP: lasts = conn.state d = conn.newstate(hbdcls.Connection.UP, now) - if d == 0 or lasts == "unknown": - m = "%s is up" % (conn.afam) - else: - m = "%s back after being %s for %s" % (conn.afam, lasts, dur(d)) - eventlog(uname, "RECOVER", m) - if uname in watchhosts: - notify_mod.pushmsg_for_host(uname, "%s %s is back" % (uname, conn.afam)) + # Don't log/notify RECOVER for a brand-new host seen for the first time — + # it was never down, it just hasn't been seen before. + if not newh: + if d == 0 or lasts == "unknown": + m = "%s is up" % (conn.afam) + else: + m = "%s back after being %s for %s" % (conn.afam, lasts, dur(d)) + eventlog(uname, "RECOVER", m) + if uname in watchhosts: + notify_mod.pushmsg_for_host(uname, "%s %s is back" % (uname, conn.afam)) if boot or newh: host.upcount = host.doesack