shell 脚本启动程序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35119182/article/details/86933721

#! /bin/bash                                                                                                                     

server_name="hello"
server_path=/home/songchao/dnschool/05shell/hello


start(){
    echo "--start-"
    ($server_path) &
    pid=$(ps -ef|grep $server_name |grep -v grep |awk '{print $2}')
    if [ ! $pid ]; then
        echo "service is not exit ..."
    else
        echo "pid=$pid"
    fi  
}

stop(){
    pid=$(ps -ef|grep $server_name |grep -v grep |awk '{print $2}')
    if [ ! $pid ]; then
        echo "service is not exit ..."
    else
        kill -9 $pid
    fi  
}

checkrun(){ 
    while true
    do
        pid=$(ps -ef|grep $server_name |grep -v grep |awk '{print $2}')
        if [[ $pid -eq 0 ]]; then
            echo "--restart-"
            start 
        fi  

        sleep 30s 
    done
} 

case $1 in
start):
    start
    ;;
stop):
    echo "--stop"
    echo $pid
    stop
    ;;
checkrun):
    echo "--restart"
    checkrun
    ;;
*):
    echo "error ..."
    ;;
esac

exit 0  

以上是一个测试用例,找一个linux程序用shell 来管理起来生命周期,现在用python 管理的比较多,简单方便约阅读一些,我公司就是用python 哈哈哈 ;

猜你喜欢

转载自blog.csdn.net/qq_35119182/article/details/86933721