Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
LinuxSystemdUnitFiles
Last updated at 10:16 pm UTC on 8 September 2017

Notes on making a program run as a service on Raspbian

As part of the WeatherStation I needed to make the (gack)Python program reading the sensors be a service that would start up after any reboot. Current Raspbian uses systemd, which h seems to be reviled and worshipped in roughly equal measure.

What worked for my purposes was adding a 'unit file' in /lib/systemd/system called 'weather.service' that consisted of
[Unit]
Description=Weather sensor read and publish
After=network-online.target
Requires=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/python /home/pi/WeatherPiMQTT/TPR-WeatherBoard-MQTT.py
Restart=on-abort

[Install]
WantedBy=multi-user.target


To start up this service you can use
sudo systemctl start weather.service


To enable it as a full service use
sudo systemctl enable weather.service


If you want more wisdom about systems - go somewhere else!