我正在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服务?非常感谢你。
答案 0 :(得分:3)
尝试使用ExecStart = / home / deploy / projects / my project / project_env / bin / python manage.py run_huey