启动脚本和守护进程

25 篇文章 0 订阅
21 篇文章 0 订阅
#!/bin/bash
# load_dypserver.sh
name='dypserver'
SV="./supervise.$name"
unalias pidof &>/dev/null
exec 0</dev/null
#ulimit -c unlimited
cd `dirname $0`

#LIBRDKAFKA_DIR=`pwd`/lib
#export LD_LIBRARY_PATH=$LIBRDKAFKA_DIR:$LD_LIBRARY_PATH

if [ ! -d "log" ]; then
        mkdir -p "log"
fi
chmod 755 log

flush_bns() {
        date >> log/boot.log
        for bns in `cat conf/*.dsn |cut -d @ -f 2|cut -d : -f 1`
        do
                echo "get_instance_by_service -a "$bns >> log/boot.log
                get_instance_by_service -a $bns >> log/boot.log
        done
        sleep 1
}

start() {
        stop
       # flush_bns
        nohup $SV bin/$name &>/dev/null &
}
stop() {
        if [ -e $SV.pid ]; then
                cat $SV.pid | xargs /usr/bin/kill
        fi
        if [[ -e /usr/bin/ps ]]; then
                pid=`/usr/bin/ps --noheaders -o pid -C $name`
        else
                pid=`ps --noheaders -o pid -C $name`
        fi
        if [ "$pid" != "" ]; then
                /usr/bin/kill $pid
        fi
        if [ -e $SV.pid ]; then
                rm $SV.pid
        fi
}
reload() {
        if [[ -e /usr/bin/ps ]]; then
                pid=`/usr/bin/ps --noheaders -o pid -C $name`
        else
                pid=`ps --noheaders -o pid -C $name`
        fi
        if [ "$pid" != "" ]; then
                /usr/bin/kill -SIGHUP $pid
        else
                start
        fi
}
case C"$1" in
        C)
                reload
                echo "Done!"
                ;;
        Cstart)
                start
                echo "Done!"
                ;;
        Cstop)
                stop
                echo "Done!"
                ;;
        Creload)
                reload
                echo "Done!"
                ;;
        C*)
                echo "Usage: $0 {start|stop|reload}"
                ;;
esac
#!/bin/bash
#!/bin/bash
# supervise.dypserver
pid=$$
echo -n "$pid" > $0.pid
app_name=$1
while [ 1 ]; do
        app_base_name=`basename $app_name`
        if [[ -e /usr/bin/ps ]]; then
                child_pid=`/usr/bin/ps  --noheaders -o pid -C $app_base_name`
        else
                child_pid=`ps  --noheaders -o pid -C $app_base_name`
        fi
        if [ "$child_pid" == "" ]; then
                /usr/bin/nohup $app_name &>/dev/null &
                wait $child_pid
        fi
        sleep 1
done

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值