shell脚本守护进程

 

概述:

守护进程是用来守护某个程序的进程,一旦程序宕机,会自动拉起

 

例子:监控一个hello.jar

vim monitor.sh

#!/bin/bash
while truedo
    num=`ps -ef|grep hello|grep -v grep|wc -l`
    if [ $num -lt 1 ];then
        nohup java -jar hello.jar &
    fi
  sleep 10 done

 

给monitor添加可执行权限,启动monitor.sh

nohup ./monitor.sh >monitor.log &

 

posted @ 2022-07-22 16:48  opscool  阅读(763)  评论(0)    收藏  举报