始终开启某个进程--shell保护STAF

由于某些原因STAF句柄可能会丢失导致该进程死掉,利用该shell脚本检查该进程是否存在,如果不存在,则自动开启,protect.sh脚本代码如下:

#!/bin/bash
while true
do
    ProcNumber=`ps -ef |grep  STAF|grep -v grep|wc -l`
    if [ $ProcNumber -le 0 ];then
        cd /usr/local/staf/bin
        nohup ./STAFProc &
        sleep 5
    fi
        PingResult=`staf localhost ping ping`
        if [[ $PingResult =~ "PONG" ]];then
                echo "staf proc can be used normally"
        else
                time=$(date "+%Y-%m-%d %H:%M:%S")
                echo "$time $PingResult" >> /home/shell/protect.log
                StafNumber=`ps -ef |grep  STAF|grep -v grep|awk '{print $2}'`
                kill -9 $StafNumber
                cd /tmp
                rm -f DataDir_*.tmp
                rm -f STAF*
        fi
done
~

写完这个很简单的shell脚本 后,开机并不能自动执行,要想开机自动执行该脚本,需做如下操作:

说明:该脚本用来保护staf进程,保证其永远为开启的状态,将该脚本放到/home/shell下,然后再在/etc/rc.d/rc.local里面添加条目:

sh  /home/shell/protect.sh 就可以实现开机启动了

发布了23 篇原创文章 · 获赞 12 · 访问量 9539

猜你喜欢

转载自blog.csdn.net/geng2568/article/details/99823129
今日推荐