- 写入
{taskname}.service
文件到/etc/systemd/system/
文件夹。 sudo systemctl daemon-reload
sudo systemctl enable {taskname}.service
sudo systemctl start {taskname}.service
systemctl status {taskname}.service
查看状态。
{taskname}.service
例子:
[Unit]
Description=Transaction
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=10
User=ubuntu
ExecStart=/usr/bin/python3 /home/ubuntu/somescript.py --arg1=2333
[Install]
WantedBy=multi-user.target
参考:https://medium.com/codex/setup-a-python-script-as-a-service-through-systemctl-systemd-f0cc55a42267