| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 | 
							- #!/bin/sh
 
- ### BEGIN INIT INFO
 
- # Provides: celeryd
 
- # Required-Start: $network $local_fs $remote_fs
 
- # Required-Stop: $network $local_fs $remote_fs
 
- # Default-Start: 2 3 4 5
 
- # Default-Stop: 0 1 6
 
- # Short-Description: celery task worker daemon
 
- ### END INIT INFO
 
- #
 
- # ============================================
 
- # celeryd - Starts the Celery worker daemon.
 
- # ============================================
 
- #
 
- # :Usage: /etc/init.d/${basename $0} {start|stop|restart|status}
 
- # :Configuration file: /etc/sysconfig/celeryd
 
- #
 
- # To implement separate init scripts, do NOT copy this script.  Instead,
 
- # symlink it.  I.e., if my new application, "little-worker" needs an init, I
 
- # should just use:
 
- #
 
- #   ln -s /etc/init.d/celeryd /etc/init.d/little-worker
 
- #
 
- # You can then configure this by manipulating /etc/sysconfig/little-worker.
 
- #
 
- # Setting `prog` here allows you to symlink this init script, making it easy
 
- # to run multiple processes on the system.
 
- prog="$(basename $0)"
 
- # Source the centos stuff
 
- . /etc/init.d/functions
 
- # Also look at sysconfig; this is where environmental variables should be set
 
- # on RHEL systems.
 
- [ -f "/etc/sysconfig/$prog" ] && . /etc/sysconfig/$prog
 
- CELERYD=${CELERYD:-"-m celery worker --detach"}
 
- CELERY=${CELERY:-"/usr/bin/celery"}
 
- CELERYD_PID_FILE=${CELERYD_PID_FILE:-"/var/run/celeryd/$prog.pid"}
 
- CELERYD_LOG_FILE=${CELERYD_LOG_FILE:-"/var/log/celeryd/$prog.log"}
 
- CELERYD_LOG_LEVEL=${CELERYD_LOG_LEVEL:-"INFO"}
 
- # This is used to change how Celery loads in the configs.  It does not need to
 
- # be set to be run.
 
- export CELERY_LOADER
 
- start_workers () {
 
-     CELERYD_LOG_DIR=$(dirname $CELERYD_LOG_FILE)
 
-     CELERYD_PID_DIR=$(dirname $CELERYD_PID_FILE)
 
-     # Ensure that the directories exist.
 
-     mkdir -p $CELERYD_LOG_DIR $CELERYD_PID_DIR
 
-     # If we specified a user, and/or a group, chown as needed
 
-     if [ -n "$CELERYD_USER" ]; then
 
-         CHOWN_UG="${CELERYD_USER}"
 
-         # If the group is specified, also use that in the chown.
 
-         [ -n "$CELERYD_GROUP" ] && CHOWN_UG="$CHOWN_UG:$CELERYD_GROUP"
 
-         # Execute the chown on the directory only
 
-         chown $CHOWN_UG $CELERYD_LOG_DIR $CELERYD_PID_DIR
 
-         CELERYD_OPTS="$CELERYD_OPTS --uid=$CELERYD_USER"
 
-     fi
 
-     # If we need to be run from a specific location, cd to it before launch
 
-     if [ -n "$CELERYD_CHDIR" ]; then
 
-         cd $CELERYD_CHDIR
 
-     fi
 
-     log_message "Starting $prog"
 
-     $CELERY multi start $prog \
 
-                                --pidfile=$CELERYD_PID_FILE \
 
-                                --logfile=$CELERYD_LOG_FILE \
 
-                                --loglevel=$CELERYD_LOG_LEVEL \
 
-                                --cmd="$CELERYD" \
 
-                                 --quiet \
 
-                                $CELERYD_OPTS
 
-     RETVAL=$?
 
-     if [ "$RETVAL" == "0" ]; then
 
-         touch /var/lock/subsys/$prog
 
-         success
 
-     else
 
-         failure
 
-     fi
 
-     echo
 
- }
 
- stop_workers () {
 
-     echo -n $"Stopping $prog: "
 
-     # If we haven't ended, explicitly kill it!
 
-     if [ ! -f $CELERYD_PID_FILE ] || [ ! -e /proc/$(cat $CELERYD_PID_FILE) ]; then
 
-         failure
 
-     echo
 
-         return
 
-     fi
 
-     # According to the latest Celery workers guide (3.0.x+), 
 
-     #  stopping workers should be via TERM signals
 
-     celerypids=$(cat $CELERYD_PID_FILE | xargs echo)
 
-     echo "Killing PIDs $celerypids"
 
-     log_message "Killing PIDs $celerypids ..." 
 
-     kill -s TERM $celerypids
 
-     RETVAL=$?
 
-     # SLeep a few seconds to make sure the process really is dead
 
-     sleep 3
 
-     # Now make sure that the process really does not exist
 
-     RETVAL=$(ps h -p $celerypids)
 
-     if [ "$RETVAL" == "" ]; then
 
-         rm -f /var/lock/subsys/$prog
 
-         log_message "SUCCESS killing PIDs $celerypids" 
 
-         success
 
-     else
 
-         log_message "FAILED killing PIDs $celerypids" 
 
-         failure
 
-     fi
 
-     echo
 
- }
 
- log_message() {
 
-     now=$(/bin/date -u "+%Y-%m-%d %H:%M:%S")
 
-     echo "[$now:] $1" >> $CELERYD_LOG_FILE
 
- }
 
- case "$1" in
 
-     start)
 
-         start_workers ;;
 
-     stop)
 
-         stop_workers ;;
 
-     status)
 
-         status -p $CELERYD_PID_FILE $prog ;;
 
-     restart)
 
-         stop_workers
 
-         start_workers ;;
 
-     *)
 
-         echo "Usage: /etc/init.d/$prog {start|stop|restart|status}"
 
-         exit 1
 
-     ;;
 
- esac
 
- exit 0
 
 
  |