进程监控代码并实现启动

  1. 添加监控脚本

    

#!/bin/bash
while true
do
    #判断pid是否存在
    pid=`ps -ef |grep "uniview"|grep -v grep`
    if [ $? -ne 0 ];then
        cd /home/soft
        nohup java -Duser.timezone=GMT+08 -jar ptg_uniview_vms_sdk-1.0.0-SNAPSHOT.jar -Xms=512M -Xmx=512M > uniview.log 2>&1 &
        echo "server uniview restart"
        timestanp=`date '+%Y-%m-%d %H:%M:%S'`
        echo "$timestanp - man 重启,请查看/home/soft/monitor.log" >>/home/soft/monitor.log
        sleep 5
    else
        echo "uniview is normal"
        sleep 10
    fi
done

 

  2.启动

 

nohup ./monitor.sh >/home/soft/monitor 2>&1 & 

 

  3.添加开机启动

  vi /etc/rc.d/rc.local 中添加 /home/soft/monitor.sh

 

posted @ 2020-08-12 14:31  ****Q  阅读(159)  评论(3)    收藏  举报