3

我在 Django 项目部署中工作。我已经集成了 huey 来运行异步任务。本地一切运行完美,但现在,在部署步骤,我遇到了关于 huey 服务激活的麻烦。我真的找不到任何相关信息,因为我认为解决方案应该如此简单,但我真的找不到它:(。

我正在使用 nginx 和 gunicorn 服务。应用程序在部署服务器上完美运行,但 huey 任务未运行。我创建了一个位于/etc/systemd/system/的 huey.service 文件,其内容如下:

[Unit]
Description=Huey Service
After=redis.service

[Service]
User=deploy
Group=www-data
WorkingDirectory=/home/deploy/projects/myproject/
ExecStart=/usr/bin/python3.6 manage.py run_huey
Restart=always

[Install]
WantedBy=multi-user.target

但我得到以下错误:

Nov 26 21:22:15 ip-172-31-11-39 python3.6[22543]:   File "manage.py", line 17, 
in <module>
Nov 26 21:22:15 ip-172-31-11-39 python3.6[22543]:  "Couldn't import Django. 
Are you sure it's installe
Nov 26 21:22:15 ip-172-31-11-39 python3.6[22543]: ImportError: Couldn't import 
Django. Are you sure it's
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: huey.service: Main process exited, 
code=exited, stat
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: huey.service: Unit entered failed state.
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: huey.service: Failed with result 'exit-code'.
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: huey.service: Service hold-off time over, scheduling
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: Stopped Huey Service.
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: huey.service: Start request repeated too quickly.
Nov 26 21:22:15 ip-172-31-11-39 systemd[1]: Failed to start Huey Service.

我认为huey服务没有检测到正在运行的virtualenv,因此找不到django(因为它在virtualenv中)但我之前已经配置了一个gunicorn服务来激活它;然后,我不知道如何说一个活动的 virtualenv 已经在运行并找到它的 huey 服务。

这是我的 gunicorn 文件配置:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=deploy
Group=www-data
WorkingDirectory=/home/deploy/projects/myproject
ExecStart=/home/deploy/projects/my project/project_env/bin/gunicorn --
access-logfile - --workers 3 --bind 
unix:/home/deploy/projects/myproject/project.sock app.wsgi:application
[Install]
WantedBy=multi-user.target

我应该如何在部署服务器上激活huey服务?太感谢了。

4

2 回答 2

3

尝试使用 ExecStart=/home/deploy/projects/my project/project_env/bin/python manage.py run_huey

于 2017-11-29T20:19:46.377 回答
0

在我的情况下,我错过了正确的环境,切换到 bash 解决了这个问题:

ExecStart=/bin/bash -c 'source /path/to/activate && /path/to/python manage.py run_huey'
于 2022-01-27T10:28:51.050 回答