在守护进程模式下启动Celery时的ImportError

时间:2017-03-07 14:51:17

标签: python celery systemd systemctl

我的Celery在CLI模式下运行良好:

  • 我的项目文件夹以这种方式组织:jive/jive.py
  • jive.py文件如下:

    app = Celery(include=['tasks.dummy_tasks','tasks.people_tasks',]) app.config_from_object(CELERY_CONFIG_PATH)

  • 我以这种方式在CLI中运行一名工作人员:celery worker -A jive当我进入jive文件夹时它就可以工作。

最近,我尝试daemonize Celery using systemd

为此,需要2个文件。我将仅为两者粘贴重要部分:

/etc/celery/conf.d

CELERYD_NODES="w1"
CELERY_BIN="/home/user1/venv/bin/celery"
CELERY_APP="jive"
CELERYD_MULTI="multi"

/etc/systemd/system/celery.service

[Service]
Type=forking
User=user1
EnvironmentFile=-/etc/celery/conf.d
WorkingDirectory=/home/user1
ExecStart=/bin/sh -c '${CELERY_BIN} multi start ${CELERYD_NODES} \
  -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE} \
  --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS}'

运行服务时,显示状态后会失败并显示以下错误:

    (venv) [user1@localhost jive]$ systemctl status celery.service
    ● celery.service - Celery Service
       Loaded: loaded (/etc/systemd/system/celery.service; disabled; vendor preset: disabled)
       Active: failed (Result: exit-code) since Tue 2017-03-07 14:59:56 CET; 2s ago
      Process: 16493 ExecStart=/bin/sh -c ${CELERY_BIN} multi start ${CELERYD_NODES}    -A ${CELERY_APP} --pidfile=${CELERYD_PID_FILE}    --logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL} ${CELERYD_OPTS} (code=exited, status=1/FAILURE)
Mar 07 14:59:56 localhost.localdomain sh[16493]: File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
Mar 07 14:59:56 localhost.localdomain sh[16493]: ImportError: No module named 'jive'
Mar 07 14:59:56 localhost.localdomain sh[16493]: celery multi v4.0.2 (latentcall)

AttributeError: 'module' object has no attribute 'celery' - &gt;我怀疑是PATH问题,但不确定如何在服务中处理这个问题。谢谢你的帮助。

0 个答案:

没有答案