rdautov / picap

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PiCap service

How to Run a Script as a Service in Raspberry Pi

Service for the Script

Now we're going to define the service to run this script:

cd /lib/systemd/system/
sudo nano picap.service

The service definition must be on the /lib/systemd/system folder. Our service is going to be called "picap.service":

[Unit]
Description=Picap Service
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/python /home/pi/PiCapExamples/Python/picap-datastream-osc-py/datastream-osc.py -h 192.168.0.52
Restart=on-abort

[Install]
WantedBy=multi-user.target

Now that we have our service we need to activate it:

sudo chmod 644 /lib/systemd/system/picap.service
chmod +x /home/pi/PiCapExamples/Python/picap-datastream-osc-py/datastream-osc.py
sudo systemctl daemon-reload
sudo systemctl enable picap.service
sudo systemctl start picap.service

Service Tasks

For every change that we do on the /lib/systemd/system folder we need to execute a daemon-reload (third line of previous code). If you want to check the status of the service, you can execute:

sudo systemctl status picap.service

In general:

Check status

sudo systemctl status picap.service

Start service

sudo systemctl start picap.service

Stop service

sudo systemctl stop picap.service

Check service's log

sudo journalctl -f -u picap.service

REFERENCES

About

License:GNU General Public License v3.0


Languages

Language:Python 100.0%