监控Linux服务器上python服务脚本

时间:2023-03-09 15:05:06
监控Linux服务器上python服务脚本

  提供给公司使用的测试平台这两天频繁地挂掉,影响到相关同事的正常使用,决定在服务器上写个监控脚本,监控到服务挂了就启动起来,一分钟检查一次。注:后台服务使用的是python。监控脚本如下:

NUM=`ps aux | grep testplan | grep -v grep |wc -l`

echo "$(date "+%Y-%m-%d %H:%M:%S") ${NUM} process found"

if [ "${NUM}" -lt "" ];then

echo "Start typ service"

cd /xxx/xxx/xxx/planservice
nohup python2. -u /xxx/xxx/xxx/run.py server -t testplan.py -t firmwaretest.py -t testtool.py -t tytest.py -t 3rdservice/testcasemanager.py -t 3rdservice/testtask.py -t 3rdservice/submittest.py -t 3rdservice/testdevice.py -c cplan.ini > ../service.log & fi

  Linux服务器上使用 crontab -e 新建定时任务:

*/ * * * * sh /data/qa/monitor/watchtyp.sh >> /data/qa/monitor/watchtyp.log

  查看任务是否启动:service crond status

  查看现有的定时任务:crontab -l

  done