diff options
| author | Matt Turner <mattst88@gmail.com> | 2026-09-09 23:51:47 -0400 |
|---|---|---|
| committer | Matt Turner <mattst88@gmail.com> | 2026-09-09 23:51:47 -0400 |
| commit | 45219840a205abc11e11f86ddfc60f87f6f6ed8b (patch) | |
| tree | b9b05194935d57db08c8387045c3e4b5159f4186 /mqtt-notify.service | |
| parent | 3c055ecf5615868d8ce9be932cddbcf59020fbab (diff) | |
The service runs for as long as the session does, so it has to survive
laptop suspends and network changes. It did not: a connection that died
while the machine was asleep could leave the client wedged, with no way
back short of restarting the unit by hand.
Tighten the reconnect behavior and add a way out when it still fails:
- Bound paho's reconnect backoff to 30 seconds. The default grows to
two minutes between attempts, so even a successful reconnect could
take minutes to happen.
- Drop the keepalive from 60 to 30 seconds so that a connection which
went away without a FIN is noticed sooner.
- Track how long we have been disconnected and exit if that exceeds
two minutes, and set Restart=always in the unit file so that systemd
brings us back with a fresh client. CLOCK_MONOTONIC excludes time
spent suspended, so this does not fire spuriously on resume.
Also stop calling sys.exit() from on_message(). It runs on paho's
network thread, where SystemExit only kills that thread and leaves the
main loop running with no connection. Quit the main loop instead.
Diffstat (limited to 'mqtt-notify.service')
| -rw-r--r-- | mqtt-notify.service | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/mqtt-notify.service b/mqtt-notify.service index 6e53ce1..ec443d8 100644 --- a/mqtt-notify.service +++ b/mqtt-notify.service @@ -7,6 +7,8 @@ Wants=network-online.target nss-lookup.target Type=simple Environment=PYTHONUNBUFFERED=1 ExecStart=%h/bin/mqtt-notify.py -c %E/%p/config +Restart=always +RestartSec=5 [Install] WantedBy=default.target |
