123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- #!/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/default/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. It
- # will still read defaults from /etc/defaults/celeryd, but everything can be
- # overriden by sysconfig.
- #
- # 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.bin.celeryd_detach"}
- CELERYD_MULTI=${CELERYD_MULTI:-"/usr/bin/celeryd-multi"}
- 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
- echo -n $"Starting $prog: "
- $CELERYD_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
- # First, try to nicely shut it down.
- $CELERYD_MULTI stop $prog --pidfile=$CELERYD_PID_FILE --quiet
- RETVAL=$?
- # SLeep a few seconds. (this was part of the original script; we can't
- # trust that it will end immediately, or that running the command will
- # stop it.
- sleep 3
- # If we haven't ended, explicitly kill it!
- if [ -f $CELERYD_PID_FILE ] && [ -e /proc/$(cat $CELERYD_PID_FILE) ]; then
- $CELERYD_MULTI stop $prog -KILL --pidfile=$CELERYD_PID_FILE --quiet
- fi
- if [ "$RETVAL" == "0" ]; then
- rm -f /var/lock/sybsys/$prog
- success
- else
- failure
- fi
- echo
- }
- 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
|