centos路径/usr/lib/systemd/system/
ubuntu路径/etc/systemd/system/
以编写myservice为例
vim /etc/systemd/system/myservice.service
内容
[Unit]
Description=This is myservice
[Service]
Type=simple
ExecStart=/usr/bin/python /home/test.py
Restart=on-failure
#必要时添加用户
#User=admin123
[Install]
WantedBy=multi-user.target
#注册
systemctl enable myservice
#启用
systemctl start myservice