Chinaunix首页 | 论坛 | 博客
  • 博客访问: 256569
  • 博文数量: 78
  • 博客积分: 1465
  • 博客等级: 上尉
  • 技术积分: 972
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-28 13:46
文章分类

全部博文(78)

文章存档

2012年(1)

2011年(9)

2010年(68)

我的朋友

分类:

2010-01-11 00:55:23

#!/bin/sh
#set -x
WORK=/home/lgr
PROGRAMNAME=test
PROGRAM=test

. /home/winks2/.bashrc


#NUMBER=`ps -ef | grep $PROGRAMNAME | grep -v $0 | grep -v grep |grep -v $PROGRAM| wc -l`
NUMBER=`ps -ef | grep $PROGRAMNAME | grep -v $0 | grep -v grep |grep -v gdb| wc -l`
check() {
                echo ""
                echo "Program $PROGRAMNAME is ${1} Running."
                echo ""
                exit 1
        }

case "$1" in
    start)
        test $NUMBER -eq 0 || check
        echo ""
        echo "Running $PROGRAM"
        echo ""
        ulimit -c unlimited
        LOGPATH=${WORK}/log
        LOGFILE=${PROGRAM}_`date '+%Y%m%d_%H%M'`
        test -d $LOGPATH || mkdir $LOGPATH
        cd $WORK
        ./${PROGRAMNAME} > $LOGPATH/out.log 2>&1 &
        ;;

    reload)

    test $NUMBER -ne 0 || check NOT
        echo ""
        echo "Reload $PROGRAM Config File"
        echo ""
        ps -ef|grep ${PROGRAMNAME} | grep -v grep |awk '{print $2}' |xargs -t -l kill -SIGHUP >/dev/null 2>&1
        ;;

   stop)
        test $NUMBER -ne 0 || check NOT
        echo ""
        echo "Stopping $PROGRAM"
        echo ""
        ps -ef|grep ${PROGRAMNAME} | grep -v grep |awk '{print $2}' |xargs -t -l kill -2 >/dev/null 2>&1
        ;;

    kill)
        test $NUMBER -ne 0 || check NOT
        echo ""
        echo "Force Stopping $PROGRAM"
        echo ""
        ps -ef|grep ${PROGRAMNAME} | grep -v grep |awk '{print $2}' |xargs -t -l kill -9 >/dev/null 2>&1
        ;;

    status)
        echo ""
        echo "Checking for $PROGRAMNAME: "
        test $NUMBER -eq 0 || check
        test $NUMBER -ne 0 || check NOT
        ;;

    restart)
        $0 stop  && sleep 1
        $0 start
        ;;

    *)
        echo ""
        echo "Usage: $0 start|stop|kill|restart|status"
        echo ""
        exit 1
        ;;
esac
阅读(613) | 评论(0) | 转发(0) |
0

上一篇:sed命令详解

下一篇:shell编程备忘录

给主人留下些什么吧!~~