1 先down脚本,将脚本放到/etc/init.d/ 目录下,名字为:celeryd
地址:
https://github.com/ask/celery/blob/master/contrib/generic-init.d/celeryd
#!/bin/sh -e
# ============================================
# celeryd - Starts the Celery worker daemon.
# ============================================
#
# :Usage: /etc/init.d/celeryd {start|stop|force-reload|restart|try-restart|status}
# :Configuration file: /etc/default/celeryd
#
# See http://docs.celeryq.org/en/latest/cookbook/daemonizing.html#init-script-celeryd
### 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
#set -e
DEFAULT_PID_FILE="/var/run/celeryd@%n.pid"
DEFAULT_LOG_FILE="/var/log/celeryd@%n.log"
DEFAULT_LOG_LEVEL="INFO"
DEFAULT_NODES="celery"
DEFAULT_CELERYD="-m celery.bin.celeryd_detach"
# /etc/init.d/celeryd: start and stop the celery task worker daemon.
CELERY_DEFAULTS=${CELERY_DEFAULTS:-"/etc/default/celeryd"}
test -f "$CELERY_DEFAULTS" && . "$CELERY_DEFAULTS"
if [ -f "/etc/default/celeryd" ]; then
. /etc/default/celeryd
fi
CELERYD_PID_FILE=${CELERYD_PID_FILE:-${CELERYD_PIDFILE:-$DEFAULT_PID_FILE}}
CELERYD_LOG_FILE=${CELERYD_LOG_FILE:-${CELERYD_LOGFILE:-$DEFAULT_LOG_FILE}}
CELERYD_LOG_LEVEL=${CELERYD_LOG_LEVEL:-${CELERYD_LOGLEVEL:-$DEFAULT_LOG_LEVEL}}
CELERYD_MULTI=${CELERYD_MULTI:-"celeryd-multi"}
CELERYD=${CELERYD:-$DEFAULT_CELERYD}
CELERYCTL=${CELERYCTL:="celeryctl"}
CELERYD_NODES=${CELERYD_NODES:-$DEFAULT_NODES}
export CELERY_LOADER
if [ -n "$2" ]; then
CELERYD_OPTS="$CELERYD_OPTS $2"
fi
CELERYD_LOG_DIR=`dirname $CELERYD_LOG_FILE`
CELERYD_PID_DIR=`dirname $CELERYD_PID_FILE`
if [ ! -d "$CELERYD_LOG_DIR" ]; then
mkdir -p $CELERYD_LOG_DIR
fi
if [ ! -d "$CELERYD_PID_DIR" ]; then
mkdir -p $CELERYD_PID_DIR
fi
# Extra start-stop-daemon options, like user/group.
if [ -n "$CELERYD_USER" ]; then
DAEMON_OPTS="$DAEMON_OPTS --uid=$CELERYD_USER"
chown "$CELERYD_USER" $CELERYD_LOG_DIR $CELERYD_PID_DIR
fi
if [ -n "$CELERYD_GROUP" ]; then
DAEMON_OPTS="$DAEMON_OPTS --gid=$CELERYD_GROUP"
chgrp "$CELERYD_GROUP" $CELERYD_LOG_DIR $CELERYD_PID_DIR
fi
if [ -n "$CELERYD_CHDIR" ]; then
DAEMON_OPTS="$DAEMON_OPTS --workdir=\"$CELERYD_CHDIR\""
fi
check_dev_null() {
if [ ! -c /dev/null ]; then
echo "/dev/null is not a character device!"
exit 1
fi
}
ensure_dir() {
if [ -d "$1" ]; then
mkdir -p "$1"
chown $CELERYD_USER:$CELERYD_GROUP "$1"
chmod 02755 "$1"
fi
}
check_paths() {
ensure_dir "$(dirname $CELERYD_PID_FILE)"
ensure_dir "$(dirname $CELERYD_LOG_FILE)"
}
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
stop_workers () {
$CELERYD_MULTI stop $CELERYD_NODES --pidfile="$CELERYD_PID_FILE"
}
start_workers () {
$CELERYD_MULTI start $CELERYD_NODES $DAEMON_OPTS \
--pidfile="$CELERYD_PID_FILE" \
--logfile="$CELERYD_LOG_FILE" \
--loglevel="$CELERYD_LOG_LEVEL" \
--cmd="$CELERYD" \
$CELERYD_OPTS
}
restart_workers () {
$CELERYD_MULTI restart $CELERYD_NODES $DAEMON_OPTS \
--pidfile="$CELERYD_PID_FILE" \
--logfile="$CELERYD_LOG_FILE" \
--loglevel="$CELERYD_LOG_LEVEL" \
--cmd="$CELERYD" \
$CELERYD_OPTS
}
case "$1" in
start)
check_dev_null
check_paths
start_workers
;;
stop)
check_dev_null
check_paths
stop_workers
;;
reload|force-reload)
echo "Use restart"
;;
status)
$CELERYCTL status $CELERYCTL_OPTS
;;
restart)
check_dev_null
check_paths
restart_workers
;;
try-restart)
check_dev_null
check_paths
restart_workers
;;
*)
echo "Usage: /etc/init.d/celeryd {start|stop|restart|try-restart|kill}"
exit 1
;;
esac
exit 0
脚本内容不用做任何更改,秩序将脚本文件变为可执行即可
2 第二个脚本,放在/etc/default/目录夏,为服务配置文件,名字为:celeryd_default
内容如下 :
# Name of nodes to start
# here we have a single node
CELERYD_NODES="w1"
# or we could have three nodes:
#CELERYD_NODES="w1 w2 w3"
# Where to chdir at start.
CELERYD_CHDIR="/Application/cooler/conf" # 为你的celeryconfig.py目录
ENV_PATH="/usr/local/bin" # 为你的python环境目录
CELERYD_MULTI="$ENV_PATH/celeryd-multi"
CELERYCTL="$ENV_PATH/celeryctl"
# Extra arguments to celeryd
CELERYD_OPTS="-l info -P eventlet -c 2 -Q celery "
# Name of the celery config module.
CELERY_CONFIG_MODULE="celeryconfig"
# %n will be replaced with the nodename.
CELERYD_LOG_FILE="/Application/cooler/logs/celery.log"
CELERYD_PID_FILE="/Application/cooler/logs/celery.pid"
# Workers should run as an unprivileged user.
CELERYD_USER="root" #系统用户名
CELERYD_GROUP="root" #系统用户群组
按照自己要求改
大功告成,自己试试吧~~~
分享到:
相关推荐
接下来,进行数据库迁移以生成Celery所需的表: ```bash python manage.py migrate ``` 在Django的`settings.py`文件中进行以下配置: 1. 添加`djcelery`到`INSTALLED_APPS`列表。 2. 设置时区为`Asia/Shanghai`。...
在一个窗口中,您正在编辑代码以尝试解决方案,而在另一个窗口中,您正在停止和启动Celery和RabbitMQ守护程序。 一遍又一遍地运行的命令可能看起来像这样: sudo /etc/init.d/rabbitmq-server restart sudo /etc/...
在`settings.py`中添加如下代码以引用配置文件: ```python # settings.py from .celery_config import * ``` ##### 3. 创建任务 创建任务通常是在某个应用的`tasks.py`文件中完成。例如: ```python # app/tasks....
使用新的后端无需更改-只需使用以下命令即可启动: paster --plugin=ckan jobs worker -c /config.ini 代替: paster --plugin=ckan celeryd run -c /config.ini 有关详细信息,请 安装 要安装ckanext-...
此扩展允许用户和服务注册以通知常见的CKAN事件,例如: 数据集事件-新增,更新,删除资源事件-新增,更新,删除订户在注册事件时会提供一个回调URL,当所需事件发生时CKAN会调用该URL。安装将Webhooks添加到您的...
在另一个标签中运行python project/manage.py celeryd 在浏览器中打开 在环境变量GITHUB_ID和GITHUB_SECRET设置您的GitHub应用程序凭据 享受 :) 部署方式 在fabfile中设置服务器设置(仅测试了Ubuntu 11.04) ...
Comandos一个Serem执行器: #Iniciar Servidor python manage.py runserver #Iniciar Redis Redis服务器 #Iniciar Celery python manage.py celeryd python manage.py celerycam
高性能计算云 目标 HPCCloud 基础设施的 Web 界面,抽象了您可以在其上运行这些模拟的模拟环境和资源。 安装 遵守; 发展 ...$ cd HPCCloud $ npm install ...(虚拟机从 HPCCloud-Deploy ...$ sudo service celeryd restar