一个监控守护进程的脚本
Eave
2014.11.28 22:12
#!/bin/sh
currPath=$(cd `dirname $0`; pwd)
list=`sed '/^#.*$/d' ${currPath}/list.list | sed '/^[\s\t]*$/d' | sed '/^$/d'`
total=5
stop()
{
echo "Stoping API MQ progress"
for i in $list;do
num=`pgrep -f $i`
pgrep -fl $i
for j in $num;do
kill $j
done
done
}
start()
{
echo "Starting API MQ progress"
for i in $list;do
num=`pgrep -fl $i | wc -l`
if [ $num -lt $total ];then
let num+=1
for curr in `seq $num $total`;do
nohup /usr/local/php/bin/php -c /usr/local/php/etc/php.ini /var/www/vhosts/api/index.php backend $i >> /tmp/${i}.log 2>&1 &
done
fi
pgrep -fl $i
done
echo "Running API MQ progress number is: `pgrep -fl backend | wc -l`"
}
restart()
{
stop
start
}
stat()
{
#echo "Total API v4.0 MQ progress is: "``
echo "API MQ progress lists"
for i in $list;do
if [ ${i:0:1} != "#" ];then
pgrep -fl $i
fi
done
echo "Running API MQ progress number is: `pgrep -fl backend | wc -l`"
}
case $1 in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
status|stat)
stat
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status|stat}"
esac