我正在尝试在 Ubuntu 服务器上部署一个 Django 项目。我遵循以下指导。
但是当我运行此命令时遇到一个问题sudo systemctl status gunicorn
,出现此错误:
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2021-08-31 20:53:12 UTC; 6min ago
TriggeredBy: ● gunicorn.socket
Process: 1918 ExecStart=/home/houssem/project/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock config.wsgi:application (code=exited, >
Main PID: 1918 (code=exited, status=3)
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1932]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1932]: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1932]: ModuleNotFoundError: No module named 'django_extensions'
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1932]: [2021-08-31 20:53:12 +0000] [1932] [INFO] Worker exiting (pid: 1932)
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1918]: [2021-08-31 20:53:12 +0000] [1918] [WARNING] Worker with pid 1931 was terminated due to signal 15
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1918]: [2021-08-31 20:53:12 +0000] [1918] [WARNING] Worker with pid 1932 was terminated due to signal 15
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1918]: [2021-08-31 20:53:12 +0000] [1918] [INFO] Shutting down: Master
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1918]: [2021-08-31 20:53:12 +0000] [1918] [INFO] Reason: Worker failed to boot.
Aug 31 20:53:12 ubuntu-20-lts systemd[1]: gunicorn.service: Main process exited, code=exited, status=3/NOTIMPLEMENTED
Aug 31 20:53:12 ubuntu-20-lts systemd[1]: gunicorn.service: Failed with result 'exit-code'.
当我运行此命令时,gunicorn config.wsgi:application --preload -b 0.0.0.0:8000
它运行正常并且我可以使用 IP 地址访问该网站。
我的gunicorn.service
和/etc/systemd/system/gunicorn.socket
文件如下所示:
# /etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/myprojectdir
ExecStart=/home/sammy/myprojectdir/myprojectenv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--bind unix:/run/gunicorn.sock \
myproject.wsgi:application
[Install]
WantedBy=multi-user.target
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
在此之前,指南中提到的所有与 gunicorn 相关的命令sudo systemctl status gunicorn
均按预期工作,并打印与指南中相同的输出。
我搜索了解决方案,但不知道如何解决这个问题,我是 gunicorn 的新手。
那么请问有人能帮我解决这个问题吗?
如果提供的信息不够,我可以提供更多细节。
编辑
关于软件包,我已经从 requirements.txt 文件在 virtualenv 中安装了软件包:pip install -r requirements.txt
。另外,我已经全局安装了 django-extension,但仍然有同样的错误。