Shell脚本重启Python程序

# restart.sh

old_pid=$(ps ax|grep Service.py|grep -v grep|awk '{print $1}') echo "old_pid=${old_pid}" if [ -z $old_pid ];then echo "Process Non-existent !" echo "Starting Process...." nohup python /home/Service.py >/dev/null 2>&1 & else kill -9 ${old_pid} mid_pid=$(ps ax|grep Service.py|grep -v grep|awk '{print $1}') if [ -z ${mid_pid} ];then echo "Process Close Success !" echo "Start Restarting....." nohup python /home/Service.py >/dev/null 2>&1 & else echo "Process Close Fail !" exit 1 fi fi new_pid=$(ps ax|grep Service.py|grep -v grep|awk '{print $1}') if [ -z ${new_pid} ];then echo "Restart Fail !" else echo "Restart Success !" echo "new_pid=${new_pid}"
原文地址:https://www.cnblogs.com/delav/p/9927289.html