linux下的python进程守护

2020-03-31  本文已影响0人  丙吉

一般情况下,运行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

上一篇 下一篇

猜你喜欢

热点阅读