https://github.com/Coxhuang/celery
centos 6.9
django==2.0.7
celery==3.1.23
django-celery==3.2.2
cd 项目根目录
celery multi start w1 -A celery_pro -l info # 开始
celery multi stop w1 -A celery_pro -l info # 结束
设置成脚本文件
vim /opt/celery_worker.sh
#!/bin/sh
case $1 in
start) cd /opt/django-celery/ && celery multi start w1 -A celery_pro -l info;; # django项目根目录 : /opt/django-celery/
stop) cd /opt/django-celery/ && celery multi stop w1 -A celery_pro -l info;; # django项目根目录 : /opt/django-celery/
*) echo "require start|stop" ;;
esac
使用
sh celery_worker.sh start # 开启
sh celery_worker.sh stop # 关闭
没有找到官方提供的beat后台运行命令,所以,自己写
新增脚本 vim /opt/celery_beat.sh
vim /opt/celery_beat.sh
#!/bin/sh
case $1 in
start) cd /opt/django-celery/ && celery -A celery_pro beat -l info > out.file 2>&1 & ;; # 启动beat ; django项目根目录 : /opt/django-celery/
esac
新增脚本 vim /opt/beat_stop.sh
vim /opt/beat_stop.sh
#!/bin/sh
PROCESS=`ps -ef|grep celery|grep -v grep|grep -v PPID|awk '{ print $2}'`
for i in $PROCESS
do
echo "Kill the $1 process [ $i ]"
kill -9 $i
done
编辑脚本 vim /opt/celery_beat.sh
vim /opt/celery_beat.sh
#!/bin/sh
case $1 in
start) cd /opt/django-celery/ && celery -A celery_pro beat -l info > out.file 2>&1 & ;; # 启动beat ; django项目根目录 : /opt/django-celery/
stop) su root /opt/beat_stop.sh start ;; # 关闭beat(根据beat_stop.sh脚本的路径适当变化)
*) echo "require start|stop" ;;
esac