github.com/unirita/cuto@v0.9.8-0.20160830082821-aa6652f877b7/_release/linux/shell/servant_service.sh (about) 1 #!/bin/bash 2 # 3 # GoCuto Starts syslogd/klogd. 4 # 5 # chkconfig: 345 99 01 6 # description: GoCuto servant for Linux is the facility run servant. 7 ### BEGIN INIT INFO 8 # Provides: $CUTO 9 ### END INIT INFO 10 11 # Source function library. 12 . /etc/init.d/functions 13 14 NAME=servant 15 LOCKFILE=/var/lock/subsys/${NAME} 16 CUTOUSER=@CUTOUSER 17 CUTOROOT=@ROOT 18 19 start() { 20 21 touch $LOCKFILE 22 #servant start 23 ISALIVE=`ps -u $CUTOUSER | grep 'servant' | grep -v grep | wc -l` 24 if [ $ISALIVE != 0 ] ; then 25 echo "#### cuto servant already Started ####" 26 exit 1 27 else 28 echo "#### cuto servant Start .. ####" 29 30 su - $CUTOUSER -c "$CUTOROOT/shell/servant.sh > $CUTOROOT/log/servant_service.log 2>&1 &" 31 32 sleep 10 33 34 nowtime=`date +"%Y/%m/%d %H:%M:%S"` 35 ISALIVE=`ps -u $CUTOUSER | grep 'servant' | grep -v grep | wc -l` 36 if [ $ISALIVE != 0 ] ; then 37 echo "$nowtime Servant process start successful." >> $CUTOROOT/log/servant_chklog.log 38 else 39 echo "$nowtime Not found Servant process." >> $CUTOROOT/log/servant_chklog.log 40 exit 1 41 fi 42 fi 43 exit 0 44 } 45 46 stop() { 47 48 rm -f $LOCKFILE 49 #servant stop 50 echo "servant Process Stopped ..." 51 52 ps -ef | grep $CUTOUSER | grep servant | grep -v grep 53 if [[ $? = 0 ]] ; then 54 nowtime=`date +"%Y/%m/%d %H:%M:%S"` 55 56 echo `ps -ef | grep $CUTOUSER | grep 'servant' | grep -v grep |awk '{print $2}'` 57 export killid=`ps -ef | grep $CUTOUSER | grep 'servant' | grep -v grep |awk '{print $2}'` 58 kill -15 $killid 59 60 echo "$nowtime Servant process stopped." >> $CUTOROOT/log/servant_chklog.log 61 else 62 echo "### servant already stopped ###" 63 fi 64 65 exit 0 66 67 return 0 68 } 69 70 case "$1" in 71 start) 72 start 73 ;; 74 stop) 75 stop 76 ;; 77 restart) 78 stop 79 sleep 1 80 start 81 ;; 82 *) 83 echo $"Usage: $0 {start|stop|restart}" 84 exit 2 85 esac 86 87 exit $?