Mosquitto reconnect after power outage on broker?

Colin Law clanlaw at gmail.com
Tue Apr 23 09:33:40 UTC 2024


On Tue, 23 Apr 2024 at 10:09, Bo Berglund <bo.berglund at gmail.com> wrote:
>
> I have a script running on boot on an Ubuntu server 20.04 LTS and its purpose is
> to log all activity on an MQTT broker. The script command is this (newsreader
> does word wrap..):
>
> CMD="mosquitto_sub -h ${BROKERIP} -i ${MQTTID} -F '@Y- at m-@d @H:@M:@S ; %t ; %p'
> -t '#' >> ${FULLOG}"
> ...
> eval "$CMD"
>
> It works well so far, but I am wondering if mosquitto will reconnect if the
> broker system experiences a power outage and is restarted when power returns?

You can do at least a partial test by disconnecting your computer from
the network for a few minutes and see if that recovers.
I suspect that mosquitto_sub will shut down with an error.

A better way to do it might be with a systemd script, then you can
control the restart on failure behaviour.

Colin



More information about the ubuntu-users mailing list