ubuntu路径 /etc/systemd/system/
1. 以编写myservice为例
vim /etc/systemd/system/myservice.service
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
注册启用service:
#注册
systemctl enable myservice
#启用
systemctl start myservice
开机后查看服务运行状态:
service newpro status
2. 注册Django自启动服务
内容:
[Unit]
Description=It is Newpro
[Service]
Type=simple
ExecStart=/usr/local/bin/python3 /opt/www/newpro/manage.py runserver 0.0.0.0:8001
#启动失败之后重启
Restart=on-failure
#重启间隔为5s
RestartSec=5s
User=admin123
[Install]
WantedBy=multi-user.target