RedHat/Fedora init script

358 views
Skip to first unread message

tinti

unread,
Aug 5, 2010, 8:22:01 AM8/5/10
to celery-users
Hi celery-users,

I'd like to share my start script for RedHat/Fedora init system. Most
parts of the script are taken from the Debian init script, but as this
one isn't usable on RedHat systems even with redhat_lsb package
installed I've started to convert and take over most part of the
script.

1. create a file /etc/init.d/celeryd with the following content:

#!/bin/bash
#
# celeryd
#
# chkconfig: - 80 05
# description: celery daemon
#

### BEGIN INIT INFO
# Provides: celeryd
# Required-Start: $remote_fs $network $rabbitmq-server $httpd
# Required-Stop: $remote_fs $network $rabbitmq-server $httpd
# Default-Start:
# Default-Stop:
# Description: celery daemon
# Short-Description: Enable Django AMQP service
### END INIT INFO

# config: /etc/sysconfig/celery
# pidfile: /var/run/celeryd.pid

# source function library
. /etc/rc.d/init.d/functions

# pull in sysconfig settings
[ -f /etc/sysconfig/celeryd ] && . /etc/sysconfig/celeryd

RETVAL=0
prog="celeryd"

# Some functions to make the below more readable
DJANGO_SETTINGS_MODULE=<DJANGO_SETTINGS>
CELERYD_PID_FILE="/var/run/celeryd.pid"
CELERYD_LOG_FILE="/var/log/celeryd.log"
CELERYD_LOG_LEVEL="INFO"
DEFAULT_CELERYD="celeryd"

export DJANGO_SETTINGS_MODULE
export DJANGO_PROJECT_DIR

if [ -z "$CELERYD" ]; then
if [ ! -z "$DJANGO_PROJECT_DIR" ]; then
CELERYD="python2.6 $DJANGO_PROJECT_DIR/manage.py"
CELERYD_OPTS="celeryd $CELERYD_OPTS"
else
CELERYD=$DEFAULT_CELERYD
fi
fi

cd $DJANGO_PROJECT_DIR

CELERYD_OPTS="$CELERYD_OPTS -f $CELERYD_LOG_FILE -l
$CELERYD_LOG_LEVEL"

if [ -n "$2" ]; then
CELERYD_OPTS="$CELERYD_OPTS $2"
fi

exec="$CELERYD $CELERYD_OPTS &"

start()
{
echo -n $"Starting $prog: "
daemon --pidfile=$CELERYD_PID_FILE $exec
RETVAL=$?
echo
[ "$RETVAL" = 0 ] && touch /var/lock/subsys/celeryd
return $RETVAL
}

stop()
{
echo -n $"Stopping $prog: "
killproc -d 10 $exec -TERM
RETVAL=$?
if [ "x$runlevel" = x0 -o "x$runlevel" = x6 ] ; then
killall $exec 2>/dev/null
fi
echo
[ "$RETVAL" = 0 ] && rm -f /var/lock/subsys/celeryd /var/run/celeryd
return $RETVAL
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status celeryd
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=1
esac
exit $RETVAL

2. Make the file executable
3. Create the file /etc/sysconfig/celeryd with the DJANGO_PROJECT_DIR
variable
4. run chkconfig --add celeryd
5. and finally chkconfig celeryd on to enable at system reboot.

That's all for now, any modifications, extensions or corrections are
warmly welcome :)

David F

unread,
Aug 19, 2010, 7:08:18 PM8/19/10
to celery-users
Thanks. This was really useful.

The only thing I'd add to this is that I'd either put
DJANGO_PROJECT_DIR right into this script and forget about /etc/
sysconfig/celeryd or break even more things out into /etc/sysconfig/
celeryd such as DJANGO_SETTINGS_MODULE more like the debian script.
Overall, this saved me rolling my own from the debian script.

This should probably be added to github under the contrib section.

Jeremy Orem

unread,
Aug 20, 2010, 7:12:12 PM8/20/10
to celery-users
A couple of potential problems:

* A pid is never written to $CELERYD_PID_FILE
* status doesn't appear to work if celeryd is started with "python2.6
$DJANGO_PROJECT_DIR/manage.py"

On Aug 5, 5:22 am, tinti <raoul.th...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages