Celery守护程序脚本不会在背景中使用init脚本

时间:2011-07-12 19:24:54

标签: python django daemon django-celery

芹菜文档说

However, in production you probably want to run the worker in the background as a daemon.

我制作了如下的init.d脚本

#!/bin/sh
#
# chkconfig: 345 99 15
# description: celery init.d 
# Where to chdir at start.
CELERYD_CHDIR="/home/username/django/django_myapp"

# How to call "manage.py celeryd_multi"
CELERYD="/opt/python27/bin/python manage.py celeryd "

#CELERYD_MULTI="$CELERYD_CHDIR/manage.py celeryd_multi"

# Extra arguments to celeryd
CELERYD_OPTS="--time-limit 300 --concurrency=8"

# Name of the celery config module.
CELERY_CONFIG_MODULE="celeryconfig"

# %n will be replaced with the nodename.
CELERYD_LOG_FILE="/var/log/celery/%n.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"

# Workers should run as an unprivileged user.
CELERYD_USER="root"
CELERYD_GROUP="celery"

# Name of the projects settings module.
export DJANGO_SETTINGS_MODULE="settings"

    CELERYD_PIDFILE=/var/run/celery.pid

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

    # Celery options
    CELERYD_OPTS="-B -l info"

    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

当我执行/etc/init.d/celeryd start

现在它运行正常,但又在前景中而不是在后台运行

是案件还是我做错了

0 个答案:

没有答案