使用systemd让程序自启保活
- 进入到“/lib/systemd/system/”目录下,并新建一个STS.service 文件,命令如下:
[Unit] Description="STS" After=network.target ntp.target [Service] Type=simple User=root ExecStart=/usr/bin/python /root/pythonProject/sts_server/httpserver.py Restart=always ExecStop= TimeoutStopSec=5 [Install] WantedBy=multi-user.target
2.将新添加的自启动服务生效
root@forlinx:~# systemctl -f enable /lib/systemd/system/MAC.service
3.启动服务
systemctl start STS