|
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.
|