比如对于/python/ceshi.py文件,如果我们想让其开机运行,并且发生错误后自动重新运行,我们可以在/etc/systemd/system目录下添加一个service文件,我们命名为ceshi.service,
然后编辑/etc/systemd/system/ceshi.service:
[Unit] Description=Ceshi Sercice After=multi-user.target network.target nss-lookup.target [Service] User=root ExecStart=python3 /python/ceshi.py Restart=on-failure [Install] WantedBy=multi-user.target
加载service配置:
systemctl daemon-reload
设置开机自启动:
systemctl enable ceshi
启动:
systemctl start ceshi
查看当前服务状态:
systemctl status ceshi