:

Celery进程定时监测

发布于:2018-4-28 9:54 作者:song100e 浏览:64 分类:Linux
#!/bin/sh

#Set param
if [ -n "$1" ];then
opt=$1
else
echo "opt is required, start or stop.";
exit;
fi

PYTHON_PATH="/usr/local/python2/bin/python"
ROOT_PATH="/data/www/vhosts/object_name/src"
CELERY_SCRIPT="/usr/bin/celery -A tasks worker --loglevel=debug --logfile=/data/www/logs/object_name/celery.log"

if [ $opt == "start" ];then
	echo "#######################"
	echo `date +%Y-%m-%d%%%H%M%S`
	programpath="${PYTHON_PATH} ${CELERY_SCRIPT}"
	n=`ps -ef |grep "${programpath}" |grep -v grep | awk '{print $2}' | wc -l`

	sleep 2
	if [ "$n" -le 0 ];then
			echo "run celery:${n}"
			cd $ROOT_PATH && $PYTHON_PATH $CELERY_SCRIPT &
	else
			echo "Celery exist:${n}"
	fi

	sleep 1
fi

if [ $opt == "stop" ];then
for line in `ps -ef | grep "${PYTHON_PATH} ${CELERY_SCRIPT}" |grep -v grep | awk '{print $2}'`
do
    kill $line
done
fi

标签: Celery

0