一般情况下,运行python脚本直接:
nohup python server.py >> log/server.log 2>&1 &
但为了保证进程不被kill掉,如下的shell脚本来维护即可。
#! /bin/bash
SCRIPT="./server.py"
while true
do
tmpstr=`ps -ef|grep ${SCRIPT}|grep -v grep|wc -l`
if [ ${tmpstr} -eq 0 ];then
nohup python $SCRIPT 1>log/server.log 2>&1 &
fi
sleep 1
done
exit 0
网友评论