Turn Your Python Script Into A Service
make sure you are running systemd, if not, apt-get install it:
systemd --version
if nothing:
sudo apt-get install -y systemd
test your python script, once you are confident it works properly, note its location
create your service with nano:
sudo nano /etc/systemd/system/servicename.service
edit in the contents:
[Unit] Description=you script's description After=multi-user.target [Service] Type=simple Restart=always ExecStart=/usr/bin/python3 /full-path/location-to/your-script.py [Install] WantedBy=multi-user.target
note: the execstart line has a command to pass a space and a location, it is easy to wipe out this entire line when copy/pasting and forgetting to add the python3 part back
make it work, make it so your service starts after reboot, and finally start your service:
sudo systemctl daemon-reload sudo systemctl enable test.service sudo systemctl start test.service
Last modified: le 2022/02/05 18:06

Discussion