init.d celery script for CentOS?

一个人想着一个人 提交于 2020-01-13 05:54:26

问题


I'm writing a Django app that uses celery. So far I've been running on Ubuntu, but I'm trying to deploy to CentOS.

Celery comes with a nice init.d script for Debian-based distributions, but it doesn't work on RedHat-based distributions like CentOS because it uses start-stop-daemon. Does anybody have an equivalent one for RedHat that uses the same variable conventions so I can reuse my /etc/default/celeryd file?


回答1:


Is better solved here:

Celery CentOS init script

You should be good using that one




回答2:


Since I didn't get an answer, I tried to roll my own:

#!/bin/sh
#
# chkconfig: 345 99 15
# description: celery init.d script

# Defines the following variables
# CELERYD_CHDIR
# DJANGO_SETTINGS_MODULE
# CELERYD
# CELERYD_USER
# CELERYD_GROUP
# CELERYD_LOG_FILE

CELERYD_PIDFILE=/var/run/celery.pid

if test -f /etc/default/celeryd; then
    . /etc/default/celeryd
fi


# Source function library.
. /etc/init.d/functions

# Celery options
CELERYD_OPTS="$CELERYD_OPTS -f $CELERYD_LOG_FILE -l $CELERYD_LOG_LEVEL"

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

start () {
        cd $CELERYD_CHDIR
        daemon --user $CELERYD_USER --pidfile $CELERYD_PIDFILE $CELERYD $CELERYD_OPTS &
}

stop () {
        if [[ -s $CELERYD_PIDFILE ]] ; then
            echo "Stopping Celery"
            killproc -p $CELERYD_PIDFILE python
            echo "done!"
            rm -f $CELERYD_PIDFILE
        else
            echo "Celery not running."
        fi    
}

check_status() {
    status -p $CELERYD_PIDFILE python
}


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


来源:https://stackoverflow.com/questions/3989656/init-d-celery-script-for-centos

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!