Service Files
We can now run services on a pi
- Create service file
sudo nano /etc/systemd/system/hubview.service
- File contents
[Unit] Description=PLC Python Service After=network.target
[Service] Type=simple User=pi WorkingDirectory=/home/pi/myproject ExecStart=/home/pi/myproject/.venv/bin/python -u run_plc.py Restart=on-failure RestartSec=2
[Install] WantedBy=multi-user.target
Commands
- sudo systemctl daemon-reload
- reload
- sudo systemctl start hubview
- sudo systemctl status hubview
- sudo systemctl enable hubview
- run on boot
- logs
- journalctl -u hubview -f
Service Creation
-
Create service sudo nano /etc/systemd/system/timelapse.service
-
Service
- [Unit] Description=Raspberry Pi Timelapse Camera After=multi-user.target
[Service] Type=simple User=pi WorkingDirectory=/home/pi/timelapse ExecStart=/usr/bin/python3 /home/pi/timelapse/timelapse.py Restart=always RestartSec=10
[Install] WantedBy=multi-user.target