Projects for the Raspberry Pi or Arduino's I have sitting around.
Logs the current temperature in the room and sends it to the Adafruit IO service.
Uses a Enviro-phat by Pimoroni sat on a Raspberry Pi Zero.
- Raspberry Pi Webcam by Jeff Geerling
For something to run, and keep running when it inevitably crashes, we can use the built in Linux process systemd
to manage it.
To get this working:
- Make sure it has the Python shebang at the top of the file
#!usr/bin/python3
- This may be different for you, try
which python
orwhich python3
to get the location on your system
- This may be different for you, try
- Make the script executable
chmod a+x your_script_filename.py
- Create the service file:
cd /etc/systemd/system
sudo touch your_service_name.service
sudo nano your_service_name.service
- Then that file needs to contain something like this:
[Unit]
Description=My service description here
[Service]
User=pi
WorkingDirectory=/home/pi
ExecStart=/path/to/your/script.py
Restart=always
[Install]
WantedBy=multi-user.target
- Then
CTRL + X
to exit, hittingY
to save - You can start the service using
sudo systemctl start your_service_name.service
- Then check on the service using
sudo systemctl status your_service_name.service
- To get it "installed" so it runs on boot
sudo systemctl enable your_service_name.service
- To "uninstall"
sudo systemctl disable your_service_name.service
- To "uninstall"
That should be it and it runs on boot. Using the journalctl
should allow to check on it and the log output
journalctl -u your_service_name -e