celery django 守护进程

celery django 守护进程

我正在尝试将 celery 与 Django 结合使用,并且能够进行设置,以便能够使用

(virtualenv)$ celery -A dbbs worker -l info

并执行Django服务器发送的任务。

现在我打算将 celery 守护进程化,但在这里失败了。我可以使用以下命令启动服务

sudo /etc/init.d/celeryd start

,但它不执行来自服务器的任务。其状态为

sudo /etc/init.d/celeryd status
* celeryd.service - LSB: celery task worker daemon
   Loaded: loaded (/etc/init.d/celeryd; bad; vendor preset: enabled)
   Active: active (exited) since Thu 2017-03-02 13:29:39 MSK; 3s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 7910 ExecStop=/etc/init.d/celeryd stop (code=exited, status=0/SUCCESS)
  Process: 7961 ExecStart=/etc/init.d/celeryd start (code=exited, status=0/SUCCESS)

Mar 02 13:29:39 77-voytekh-mysql systemd[1]: Starting LSB: celery task worker daemon...
Mar 02 13:29:39 77-voytekh-mysql celeryd[7961]: celery init v10.1.
Mar 02 13:29:39 77-voytekh-mysql celeryd[7961]: /etc/init.d/celeryd: 46: /etc/init.d/celeryd: [[: not found
Mar 02 13:29:39 77-voytekh-mysql celeryd[7961]: Using config script: /etc/default/celeryd
Mar 02 13:29:39 77-voytekh-mysql celeryd[7961]: celery daemon disabled - see /etc/default/celeryd
Mar 02 13:29:39 77-voytekh-mysql systemd[1]: Started LSB: celery task worker daemon.

并且服务器请求的任何任务似乎都会进入某个队列,因为如果我使用“celery -A dbbs worker -l info”手动启动 celery,它们会立即执行。Django 服务器在虚拟环境中工作,并且 celery 也安装在该环境中。

我的 celeryd 配置文件如下。有人能提示一下哪里出了问题吗?

CELERYD_NODES="dbbs_worker"

CELERY_BIN="/home/voytekh/Env/bdds/bin/celery"

CELERY_APP="dbbs"
#CELERY_APP="proj.tasks:app"

CELERYD_CHDIR="/home/voytekh/dbbs/"

CELERYD_OPTS="--time-limit=300 --concurrency=8"
#CELERYD_OPTS="--time-limit=300 -c 8 -c:worker2 4 -c:worker3 2 -Ofair:worker1"

CELERYD_LOG_LEVEL="DEBUG"

CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"

CELERYD_USER="celery"
CELERYD_GROUP="celery"

更新:

/etc/init.d/celeryd:46:/etc/init.d/celeryd:[[:未找到- 通过编辑解决/etc/init.d/celeryd如图所示https://github.com/celery/celery/commit/44c0ebf9c46406988e5002f8a78aa2dd506451d6 然后你需要添加已启用=真设置来告诉脚本启动守护进程。

使用 sudo /etc/init.d/celeryd start 启动时仍然出现错误:

$ sudo /etc/init.d/celeryd status
* celeryd.service - LSB: celery task worker daemon
   Loaded: loaded (/etc/init.d/celeryd; bad; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2017-03-02 13:39:25 MSK; 4s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 8265 ExecStop=/etc/init.d/celeryd stop (code=exited, status=0/SUCCESS)
  Process: 8632 ExecStart=/etc/init.d/celeryd start (code=exited, status=1/FAILURE)

Mar 02 13:39:25 77-voytekh-mysql systemd[1]: Starting LSB: celery task worker daemon...
Mar 02 13:39:25 77-voytekh-mysql celeryd[8632]: celery init v10.1.
Mar 02 13:39:25 77-voytekh-mysql celeryd[8632]: Using config script: /etc/default/celeryd
Mar 02 13:39:25 77-voytekh-mysql su[8651]: Successful su for celery by root
Mar 02 13:39:25 77-voytekh-mysql su[8651]: + ??? root:celery
Mar 02 13:39:25 77-voytekh-mysql su[8651]: pam_unix(su:session): session opened for user celery by (uid=0)
Mar 02 13:39:25 77-voytekh-mysql systemd[1]: celeryd.service: Control process exited, code=exited status=1
Mar 02 13:39:25 77-voytekh-mysql systemd[1]: Failed to start LSB: celery task worker daemon.
Mar 02 13:39:25 77-voytekh-mysql systemd[1]: celeryd.service: Unit entered failed state.
Mar 02 13:39:25 77-voytekh-mysql systemd[1]: celeryd.service: Failed with result 'exit-code'.
Warning: celeryd.service changed on disk. Run 'systemctl daemon-reload' to reload units.

更新2: 详细的启动日志显示它在处理 /bin/echo -e 时失败。到目前为止,我不明白这意味着什么。

$ sh -x /etc/init.d/celeryd start
+ . /lib/lsb/init-functions
+ run-parts --lsbsysinit --list /lib/lsb/init-functions.d
+ [ -r /lib/lsb/init-functions.d/01-upstart-lsb ]
+ . /lib/lsb/init-functions.d/01-upstart-lsb
+ unset UPSTART_SESSION
+ _RC_SCRIPT=/etc/init.d/celeryd
+ [ -r /etc/init//etc/init.d/celeryd.conf ]
+ _UPSTART_JOB=celeryd
+ [ -r /etc/init/celeryd.conf ]
+ [ -r /lib/lsb/init-functions.d/20-left-info-blocks ]
+ . /lib/lsb/init-functions.d/20-left-info-blocks
+ [ -r /lib/lsb/init-functions.d/40-systemd ]
+ . /lib/lsb/init-functions.d/40-systemd
+ _use_systemctl=0
+ [ -d /run/systemd/system ]
+ prog=celeryd
+ service=celeryd.service
+ systemctl -p LoadState show celeryd.service
+ state=LoadState=loaded
+ [ LoadState=loaded = LoadState=masked ]
+ [ 1642 -ne 1 ]
+ [ -z  ]
+ [ -z  ]
+ readlink -f /etc/init.d/celeryd
+ _use_systemctl=1
+ systemctl -p CanReload show celeryd.service
+ [ CanReload=no = CanReload=no ]
+ [ start = reload ]
+ [ 1 = 1 ]
+ set +e
+ set +u
+ [ xstart = xstart -o xstart = xstop -o xstart = xrestart -o xstart = xreload -o xstart = xforce-reload -o xstart = xstatus ]
+ systemctl_redirect /etc/init.d/celeryd start
+ local s
+ local rc
+ local prog=celeryd
+ local command=start
+ s=Starting celeryd (via systemctl)
+ service=celeryd.service
+ systemctl is-system-running
+ OUT=degraded
+ [ degraded != degraded ]
+ [ start = status ]
+ log_daemon_msg Starting celeryd (via systemctl) celeryd.service
+ [ -z Starting celeryd (via systemctl) ]
+ log_daemon_msg_pre Starting celeryd (via systemctl) celeryd.service
+ log_use_fancy_output
+ TPUT=/usr/bin/tput
+ EXPR=/usr/bin/expr
+ [ -t 1 ]
+ [ xxterm-256color != x ]
+ [ xxterm-256color != xdumb ]
+ [ -x /usr/bin/tput ]
+ [ -x /usr/bin/expr ]
+ /usr/bin/tput hpa 60
+ /usr/bin/tput setaf 1
+ [ -z ]
+ FANCYTTY=1
+ true
+ echo -n [....] 
[....] + [ -z celeryd.service ]
+ echo -n Starting celeryd (via systemctl): celeryd.service
Starting celeryd (via systemctl): celeryd.service+ log_daemon_msg_post Starting celeryd (via systemctl) celeryd.service
+ :
+ /bin/systemctl --no-pager start celeryd.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'celeryd.service'.
Multiple identities can be used for authentication:
 1.  miv,,, (miv)
 2.  voytekh
Choose identity to authenticate as (1-2): 2
Password: 
==== AUTHENTICATION COMPLETE ===
Warning: celeryd.service changed on disk. Run 'systemctl daemon-reload' to reload units.
Job for celeryd.service failed because the control process exited with error code. See "systemctl status celeryd.service" and "journalctl -xe" for details.
+ rc=1
+ [ start = status ]
+ log_end_msg 1
+ [ -z 1 ]
+ local retval
+ retval=1
+ log_end_msg_pre 1
+ log_use_fancy_output
+ TPUT=/usr/bin/tput
+ EXPR=/usr/bin/expr
+ [ -t 1 ]
+ [ xxterm-256color != x ]
+ [ xxterm-256color != xdumb ]
+ [ -x /usr/bin/tput ]
+ [ -x /usr/bin/expr ]
+ /usr/bin/tput hpa 60
+ /usr/bin/tput setaf 1
+ [ -z 1 ]
+ true
+ true
+ /usr/bin/tput setaf 1
+ RED=
+ /usr/bin/tput setaf 2
+ GREEN=
+ /usr/bin/tput setaf 3
+ YELLOW=
+ /usr/bin/tput op
+ NORMAL=
+ /usr/bin/tput civis
+ /usr/bin/tput sc
+ /usr/bin/tput hpa 0
+ [ 1 -eq 0 ]
+ [ 1 -eq 255 ]
+ /bin/echo -ne [FAIL
[FAIL+ /usr/bin/tput rc
+ /usr/bin/tput cnorm
+ log_use_fancy_output
+ TPUT=/usr/bin/tput
+ EXPR=/usr/bin/expr
+ [ -t 1 ]
+ [ xxterm-256color != x ]
+ [ xxterm-256color != xdumb ]
+ [ -x /usr/bin/tput ]
+ [ -x /usr/bin/expr ]
+ /usr/bin/tput hpa 60
+ /usr/bin/tput setaf 1
+ [ -z 1 ]
+ true
+ true
+ /usr/bin/tput setaf 1
+ RED=
+ /usr/bin/tput setaf 3
+ YELLOW=
+ /usr/bin/tput op
+ NORMAL=
+ [ 1 -eq 0 ]
+ [ 1 -eq 255 ]
+ /bin/echo -e  failed!
 failed!
+ log_end_msg_post 1
+ :
+ return 1
+ return 1
+ exit 1

答案1

我遇到了一个非常相似的问题,结果证明是我的更改目录的执行权限。

因此,就我的情况而言,是这样的:

sudo chmod o+x /home/voytekh/dbbs/

让它工作了。

注意:这是不是启用所需权限的最佳方法,但这与该答案无关。

相关内容