Tuesday, May 21, 2019

How to run pyradmon.py in Systemd on Ubuntu 18.04.2-LTS

pyradmon.py is a little python script I need running to get data from my Geiger counter (GMC-320) to its data showing webpage (Radmon.org).
The script has to always run, also after reboots, outages, changes to the system or the script itself, and it has to be restarted if it fails.
On Ubuntu 18 and many other systems a system called Systemd is in use to facilitate this.

To get the script running in systemd do the following:

Create a file called "radmon.service" in /etc/systemd/system .
[Unit]
Description=Radmon service
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=30
User=marc
ExecStart=/usr/bin/python -u /home/marc/GMC/pyradmon.py
StandardOutput=null
StandardError=inherit

[Install]
WantedBy=multi-user.target
Then do:
sudo systemctl enable radmon.service
sudo systemctl start radmon.service
And if needed do:
sudo systemctl status radmon.service
sudo systemctl restart radmon.service
sudo systemctl stop radmon.service
That's it.

No comments:

Post a Comment