#!/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
阅读(737) | 评论(0) | 转发(0) |