#!/bin/bash pidPath="../runtime/dbevent_worker.pid" phpbin="/alidata/server/php/bin/php" logFile="../runtime/dbevent_worker.log" cd /alidata/www/zhipuzi-test2/cysystem/scripts #dbevent worker stop() { if [ -f $pidPath ]; then pid=`cat $pidPath` echo "stop dbevent worker, pid="$pid"..." check_exist pidIsExits=$? if [ $pidIsExits -eq 1 ]; then kill $pid else echo "dbevent worker not exist." rm -f $pidPath fi try=0 while test $try -lt 60; do if [ ! -f "$pidPath" ]; then try='' break fi echo -n try=`expr $try + 1` sleep 1 done echo "stop dbevent worker ok." fi } #启动worker start() { check_exist pidIsExits=$? if [ $pidIsExits -eq 1 ]; then echo "dbevent worker had running..." else echo "start dbevent worker..." groupName=$1 cmd=$phpbin" dbeventWorker.php -d -g"$groupName $cmd &> $logFile fi } #检测worker进程是否存在 check_exist() { if [ ! -f $pidPath ]; then return 0 fi pid=`cat $pidPath` pids=`ps aux | grep dbeventWorker.php | grep -v grep | awk '{print $2}'` pidIsExits=0; for i in ${pids[@]} do if [ "$i" -eq "$pid" ]; then pidIsExits=1 break fi done return $pidIsExits } case "$1" in start) start $2 ;; stop) stop ;; *) echo $"Usage: dbeventWorker.sh {start|stop|help}" exit 1 esac