1. 写入{taskname}.service文件到/etc/systemd/system/文件夹。
  2. sudo systemctl daemon-reload
  3. sudo systemctl enable {taskname}.service
  4. sudo systemctl start {taskname}.service
  5. 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