Long Running Processes
I had a Python script which kept dying on me. This script read from the MQTT server that my temperature sensors output to; everytime there was an incoming message received, the script will pick up the change and automatically write the payload to a table in MySQL.
While I could rewrite the MySQL Python connector to reconnect in the event of a timeout, it was much easier to use SystemD to restart the process whenever it terminated.
root@mhlprmq01:~# cat /etc/systemd/system/mqtt2mysql.service
[Unit]
Description=MQTT to MySQL
After=network.target
[Service]
ExecStart=/opt/scripts/mqtt2mysql.py
Restart=always
KillMode=process
[Install]
WantedBy=multi-user.target