Daemonizing paster celeryd?

158 views
Skip to first unread message

mbrownnyc

unread,
Oct 25, 2011, 11:31:35 AM10/25/11
to rhodecode
Hello,

How do I daemonize the paster celeryd process?

It seems that notes mentioned in https://github.com/ask/celery/issues/373
do not apply to the paster command (--detach is unavailable).


Any assistance would be greatly appreciated.


Thanks,

Matt

lance dillon

unread,
Oct 28, 2011, 8:17:58 AM10/28/11
to rhod...@googlegroups.com
I created a init script to do that, I can post it if you want.

mbrownnyc

unread,
Oct 31, 2011, 10:52:34 AM10/31/11
to rhodecode
Yes, please do, as it's likely much better than this one I wrote:

#!/bin/sh
#
#
#
#
# chkconfig: 345 80 05
# description:
#init script for paste script celeryd, which was written by
#branded on freenode
#mbrownnyc everywhere else
#hacky init.d script for celeryd paste script
#

### BEGIN INIT INFO
# Provides: paste-script-celeryd
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Description: Paste Script to launch celeryd reading config out
of a paste config file
### END INIT INFO

case "$1" in
start)
if [ ! -f /var/run/celeryd.pid ]; then #process isn't running
probably
echo Attempting to start celeryd paste script...
forking it up with \&
export HOME=/root #well... yea, this has to do with
previous steps, I'll have to review how to modify this so it's less
horrible.
/var/www/rhodecode-venv/bin/paster celeryd /var/www/
rhodecode/production.ini --pidfile=/var/run/celeryd.pid -f /var/log/
celerydpaster.log -l WARNING -q &
echo Done.
else
echo The celeryd paste script has filed a paste PID $
(cat /var/run/celeryd.pid)
echo It\'s likely started already at that PID.
fi
;;
stop)
if [ -f /var/run/celeryd.pid ]; then #process is running
probably
echo sending SIGINT to the process $(cat /var/run/
celeryd.pid) to trigger a "Warm shutdown"
pypastceleryPID=$(cat /var/run/celeryd.pid)
kill -SIGINT $pypastceleryPID
echo Waiting for process to die...
#umm... yea!
http://stackoverflow.com/questions/696839/how-do-i-write-a-bash-script-to-restart-a-process-if-it-dies
while [ -f /var/run/celeryd.pid ]; do sleep 1; done
echo Truncating /var/log/celerydpaster.log to entries
from last run only.
sed -i '1,'$(expr $(grep -n -e "^----\s\*\*\*\*
\s-----" /var/log/celerydpaster.log | cut -d':' -f1 | awk '$1 > max
{ max=$1 }; END { print max }') - 1)'d' /var/log/celerydpaster.log
else
echo /var/run/celeryd.pid doesn\'t exist, so the
celeryd paste script was not used to execute celeryd if celeryd is
actually running.
echo Otherwise it isn\'t running.
fi
;;
restart)
stop
start
;;
status)
if [ -f /var/rrun/celeryd.pid ]; then
echo celeryd paste script is running as PID $(cat /var/
run/celeryd.pid)
tail -n 20 /var/log/celerydpaster.log
else
echo celeryd paste script isn\'t running.
fi

;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
;;
esac
exit 1


On Oct 28, 8:17 am, lance dillon <riffraff...@gmail.com> wrote:
> I created a init script to do that, I can post it if you want.
>
>
>
>
>
>
>
> On Tue, Oct 25, 2011 at 11:31 AM, mbrownnyc <matthewbr...@gmail.com> wrote:
> > Hello,
>
> > How do I daemonize the paster celeryd process?
>
> > It seems that notes mentioned inhttps://github.com/ask/celery/issues/373

lance dillon

unread,
Oct 31, 2011, 11:01:05 AM10/31/11
to rhod...@googlegroups.com
#!/bin/sh
#
# celeryd     This shell script starts the celeryd daemon
#
# chkconfig: - 86 04
# description: celeryd is a queue manager for rhodecode
#
. /etc/rc.d/init.d/functions

. /etc/sysconfig/network

if [ -f /etc/sysconfig/celeryd ]; then
    . /etc/sysconfig/celeryd
fi

[ ${NETWORKING} = "no" ] && exit 0

RETVAL=0
prog="celeryd"
script="/var/www/rhodecode-venv/bin/python"

start() {
    echo -n "Starting $prog: "
    . $APP_PATH/bin/activate
    daemon --pidfile $PID_PATH --user $USER "PYTHON_EGG_CACHE=$PYTHON_EGG_CACHE $PROG_BIN $prog $APP_PATH/$CONF_NAME &"
    PID=$(ps -C paster -o user,pid,ppid,comm,args -ww|grep celeryd|awk '$3 ~ /^1$/ { print $2 }')
    echo $PID > $PID_PATH
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then echo_success; else echo_failure; fi
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
    return $RETVAL
}

stop() {
    echo -n "Shutting down $prog: "
#    killproc -p $PID_PATH $prog
    kill $(cat $PID_PATH)
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
    return $RETVAL
}

case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart|reload)
    stop
    start
    ;;
    status)
    status "$script"
    RETVAL=$?
    ;;
    condrestart)
    if status "$script" >/dev/null; then
        stop
        start
    fi
    ;;
    *)
    echo $"Usage: $0 {start|stop|restart|reload|status|condrestart}"
    exit 1
esac

exit $RETVAL

##############33
# /etc/sysconfig/celeryd
USER=hg
GROUP=hg
APP_HOMEDIR=/var/www/rhodecode-venv
APP_PATH=$APP_HOMEDIR
CONF_NAME=production.ini
PID_PATH=$APP_HOMEDIR/celeryd.pid
LOG_PATH=$APP_HOMEDIR/celeryd.log
PYTHON_PATH=$APP_HOMEDIR/bin
PROG_BIN=$PYTHON_PATH/paster
PYTHON_EGG_CACHE=/tmp


Obviously this is for red hat derived systems.  You can alter it for whatever system you are using.  I'm not sure it is better than what you had, but it definitely does the job for me.
Reply all
Reply to author
Forward
0 new messages