用supervisor控制celery時的腳本

注意啓停的前後順序及判斷便可。html

這樣,在更改task以後,要重啓就方便不少啦。。python

#!/bin/sh

supervisord_count=`ps -elf | grep celery | grep -v grep | wc -l`
if [ $supervisord_count -gt 0 ]; then
    ps aux|grep -v grep|grep supervisord|awk '{print $2}'|xargs kill -9
fi

celery_count=`ps -elf | grep celery | grep -v grep | wc -l`
if [ $celery_count -gt 0 ]; then
    ps aux|grep -v grep|grep celery|awk '{print $2}'|xargs kill -9
fi

/usr/bin/python /usr/local/python27/bin/supervisord -c /P/supervisord_prd.conf
sh /usr/local/nginx/sbin/uwsgi9090 reload
/usr/local/nginx/sbin/nginx -s reload

echo 'finished!'

另給一個最基本的supervisor的設置:nginx

; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
;  - Shell expansion ("~" or "$HOME") is not supported.  Environment
;    variables can be expanded using this syntax: "%(ENV_HOME)s".
;  - Comments must have a leading space: "a=b ;comment" not "a=b;comment".

[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
loglevel=info                ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false               ; (start in foreground if true;default false)
minfds=1024                  ; (min. avail startup file descriptors;default 1024)
minprocs=200                 ; (min. avail process descriptors;default 200)
;umask=022                   ; (process file creation umask;default 022)
;user=chrism                 ; (default is current user, required if root)
;identifier=supervisor       ; (supervisord identifier, default is 'supervisor')
;directory=/tmp              ; (default is not to cd during start)
;nocleanup=true              ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
;environment=KEY="value"     ; (key value pairs to add to environment)
;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[program:celeryd]
command=/usr/local/python27/bin/celery worker -A XXXX -c 4   -l INFO -n celeryd@deploy
stdout_logfile=/var/log/celeryd.log
stderr_logfile=/var/log/celeryd.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=600

;[program:celerybeat]
;command=/usr/local/python27/bin/celery worker -A XXXX -c 4   -B -n celerybeat@ping
;stdout_logfile=/var/log/celeryd.log
;stderr_logfile=/var/log/celeryd.log
;autostart=true
;autorestart=true
;startsecs=10
;stopwaitsecs=600
相關文章
相關標籤/搜索