美文网首页
linux shell脚本监控进程崩溃自动重启

linux shell脚本监控进程崩溃自动重启

作者: 弹猪 | 来源:发表于2018-05-30 16:46 被阅读0次

优化了一下别人写法,code如下

# ! /bin/sh

SERVICE_PATH="/data/www/ec"

SERVICE_NAME="go-mysql-sync"

START_CMD="./$SERVICE_NAME -config=river.toml"

LOG_FILE="restart.log"


cd $SERVICE_PATH

pwd

while true 

do

    procnum=`ps -ef|grep $SERVICE_NAME|grep -v grep|wc -l`

    if [ $procnum -eq 0 ]

    then

        echo "start service...................."

        echo `date +%Y-%m-%d` `date +%H:%M:%S`  $SERVICE_NAME >>$LOG_FILE

        ${START_CMD}

    fi

    sleep 1 //每秒检查一轮

done

最后nohup 运行这个shell

nohup ./elastic.sh >/dev/null 2>&1 &

相关文章

网友评论

      本文标题:linux shell脚本监控进程崩溃自动重启

      本文链接:https://www.haomeiwen.com/subject/wqkxsftx.html