
我正在嘗試在 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,但仍然有相同的錯誤。