Community
OpenEnergyMonitor

OpenEnergyMonitor Community

Emoncms_mqtt fails to log measurements after mariadb update

Hi,

This morning after my emonPi’s (was Oct 2019 version) updated mariadb (I have RPI unattended upgrades installed) I found that nothing had been logged for a few hours - after a bit of fiddling around I found that restarting the emoncms_mqtt service go things working again.

Having found that there was a new image available (July 2020) I put that on a new SD card and booted up, setup my own hostnames and imported the data from the previous SD card and then installed the RPI unattended-upgrades package and allowed it to update to the latest packages and when it updated mariadb the system stopped logging any values.

until emoncms_mqtt was restarted the values where not appearing in the ‘Input’ view or in ‘Feeds’.

The emoncms.log shows:

2020-10-22 12:49:35.056|WARN|emoncms_mqtt.php|mysql ping false
2020-10-22 12:56:33.275|WARN|emoncms_mqtt.php|Not connected, retrying connection
2020-10-22 12:56:33.335|WARN|emoncms_mqtt.php|Connecting to MQTT server: Connection Accepted.: code: 0

around the time of the update of mariadb and my restart of emoncms_mqtt

It seems to me that it would be better if emoncms_mqtt retried the connection after a short time or if the enforced restart of mariadb in the update process would restart emoncms_mqtt - is this not possible with the correct systemd configuration of emoncms_mqtt ?

Well my solution to try to prevent the same issue again is

from ssh session:

sudo systemctl edit emoncms_mqtt.service

insert:

[Unit]
Requires=mariadb.service mosquitto.service

save the changes.

This should (and testing seems to show it does) mean that the emoncms_mqtt service is restarted whenever either the mariadb or mosquitto services which might cause similar issues are restarted.

I’m not a fan of just running upgrades - you never know what it might break :slight_smile:.

It would appear to be the way this package works rather than a general problem.

The service file uses the weaker version wants because there are circumstances when the SQL database or the MQTT broker may be on a different server. Not ideal I know.