起初使用nohup运行服务
nohup python3 -u ./xxxx.py > ./logs 2>&1 &
发现过几天就会跪掉。
解决方案:
1.写重启项目的脚本(先杀死进程后启动,否则启动失败)
# vim start
文本内容:
ps -ef|grep xxxx.py|grep python|awk '{print $2}'|xargs kill -9
nohup python3 -u ./xxxx.py > ./logs 2>&1 &
wq保存。
2.添加定时任务
# crontab -e
i编辑添加行(每天4:45定时运行start文件重启任务)
45 4 * * * /root/wx/start
参考:
https://blog.csdn.net/u010976445/article/details/50819287