您的位置:首页 > 运维架构

一个短小精悍的监控/守护进程

2012-05-28 12:00 477 查看

一个短小精悍的监控/守护进程

Author: 柳大·Poechant(钟超)
Email: zhongchao.ustc#gmail.com
Blog: Blog.CSDN.net/Poechant
Date: May 28th, 2012
#!/bin/bash

YOUR_TARGET = your_target

while:
do
    echo "Current DIR is " $PWD
    stillRunning = $(ps -ef | grep "$PWD/$YOUR_TARGET" | grep -v "grep")
    if [ "$stillRunning" ]; then
        echo "You target service was already started by another way"
        echo "Kill it and then startup by this shell, otherwise this shell will loop out this message annoyingly"
        kill -9 $pidof $PWD/$YOUR_TARGET
    else
        echo "Your target service was not started"
        echo "Starting service …"
        $PWD/$YOUR_TARGET &
        echo "Your target service was exited!"
    fi
    sleep 10
done
grep -v
: –invert-match. Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.)
-转载请注明来自柳大的CSDN博客:Blog.CSDN.net/Poechant-
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: