Sennevds / system_sensors

Logging of system sensor specific for the RPI and sending them to a MQTT broker
MIT License
367 stars 113 forks source link

service could use an auto-restart #60

Closed XPav closed 4 years ago

XPav commented 4 years ago

On startup, I get the following errors from system_sensors

Oct 06 15:22:48 augmntrpi python3[618]: Traceback (most recent call last):
Oct 06 15:22:48 augmntrpi python3[618]:   File "/home/pi/system_sensors/src/system_sensors.py", line 436, in <module>
Oct 06 15:22:48 augmntrpi python3[618]:     mqttClient.connect(settings["mqtt"]["hostname"], settings["mqtt"]["port"])
Oct 06 15:22:48 augmntrpi python3[618]:   File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py", line 9
Oct 06 15:22:48 augmntrpi python3[618]:     return self.reconnect()
Oct 06 15:22:48 augmntrpi python3[618]:   File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py", line 1
Oct 06 15:22:48 augmntrpi python3[618]:     sock = self._create_socket_connection()
Oct 06 15:22:48 augmntrpi python3[618]:   File "/home/pi/.local/lib/python3.7/site-packages/paho/mqtt/client.py", line 3
Oct 06 15:22:48 augmntrpi python3[618]:     return socket.create_connection(addr, source_address=source, timeout=self._k
Oct 06 15:22:48 augmntrpi python3[618]:   File "/usr/lib/python3.7/socket.py", line 707, in create_connection
Oct 06 15:22:48 augmntrpi python3[618]:     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
Oct 06 15:22:48 augmntrpi python3[618]:   File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
Oct 06 15:22:48 augmntrpi python3[618]:     for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
Oct 06 15:22:48 augmntrpi python3[618]: socket.gaierror: [Errno -3] Temporary failure in name resolution
Oct 06 15:22:48 augmntrpi systemd[1]: system_sensors.service: Main process exited, code=exited, status=1/FAILURE
Oct 06 15:22:48 augmntrpi systemd[1]: system_sensors.service: Failed with result 'exit-code'.

This is because the wifi hasn't fully connected or something similar.

To solve this, I added some auto-restart lines in the service definition. These may be useful for other users.

[Unit]
Description=System Sensor service
After=multi-user.target

StartLimitIntervalSec=500
StarLimitBurst=5

[Service]
User=pi
Type=idle
ExecStart=/usr/bin/python3 /home/pi/system_sensors/src/system_sensors.py /home/pi/system_sensors/src/settings.yaml
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target
Sennevds commented 4 years ago

Check #59

moto3001 commented 4 years ago

'StarLimitBurst=5'

I think you meant: StartLimitBurst