Systemd service
Ref here
- Setup script to run as service called test.py
import time from datetime import datetime while True: with open("timestamp.txt", "a") as f: f.write("The current timestamp is: " + str(datetime.now())) f.close() time.sleep(10)
- nano /etc/systemd/system/test.service (name of the service which is test in this case)
[Unit] Description=My test service After=multi-user.target [Service] Type=simple Restart=always ExecStart=/usr/bin/python3 /home/<username>/test.py [Install] WantedBy=multi-user.target
- reload systemctl daemon
sudo systemctl daemon-reload sudo systemctl enable test.service sudo systemctl start test.service sudo systemctl stop test.service sudo systemctl restart test.service sudo systemctl status test.service
Last modified 3 years ago
Last modified on 04/05/22 03:31:55