Shell脚本重启Python程序
# restart.sh
old_pid=$(ps ax|grep Service.py|grep -v grep|awk '{print $1}')shell程序的编写流程
echo "old_pid=${old_pid}"
if [ -z $old_pid ];then
echo "Process Non-existent !"
echo ""
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 ""
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}"

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。