测试套接字激活失败,Django 和 Gunicorn

Testing socket activation failed, Django and Gunicorn

当我尝试这样做时:

sudo systemctl status gunicorn

它的回答是:

Failed to dump process list, ignoring: No such file or directory
● gunicorn.socket - gunicorn socket
   Loaded: loaded (/etc/systemd/system/gunicorn.socket; enabled; vendor preset: enabled)
   Active: active (listening) since Wed 2019-09-25 04:23:44 UTC; 3min 27s ago
   Listen: /run/gunicorn.sock (Stream)
   CGroup: /system.slice/gunicorn.socket

Sep 25 04:23:44 myproject systemd[1]: Listening on gunicorn socket.
root@myproject :/myprojectdir# sudo systemctl status gunicorn
● gunicorn.service - gunicorn daemon
   Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2019-09-25 04:27:02 UTC; 13s ago
 Main PID: 25219 (code=exited, status=3)

Sep 25 04:27:02 myproject gunicorn[25219]:   File "/myprojectdir/myprojectenv/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
Sep 25 04:27:02 myproject gunicorn[25219]:     return util.import_app(self.app_uri)
Sep 25 04:27:02 myproject gunicorn[25219]:   File "/myprojectdir/myprojectenv/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
Sep 25 04:27:02 myproject gunicorn[25219]:     __import__(module)
Sep 25 04:27:02 myproject gunicorn[25219]: ModuleNotFoundError: No module named 'myproject'
Sep 25 04:27:02 myproject gunicorn[25219]: [2019-09-25 04:27:02 +0000] [25245] [INFO] Worker exiting (pid: 25245)
Sep 25 04:27:02 myproject gunicorn[25219]: [2019-09-25 04:27:02 +0000] [25219] [INFO] Shutting down: Master
Sep 25 04:27:02 myproject gunicorn[25219]: [2019-09-25 04:27:02 +0000] [25219] [INFO] Reason: Worker failed to boot.
Sep 25 04:27:02 myproject systemd[1]: gunicorn.service: Main process exited, code=exited, status=3/NOTIMPLEMENTED
Sep 25 04:27:02 myproject systemd[1]: gunicorn.service: Failed with result 'exit-code'.

它似乎在尝试寻找 myproject.wsgi,但我从未创建过,而且我遵循的教程也没有提及它。 但是,它应该回答这个问题:

● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; disabled; vendor preset: enabled)
Active: inactive (dead)

感谢任何帮助,如果我没有提供任何有用的信息,我很抱歉,但我不知道我还能提供什么。我正在使用:Google Cloud Ubuntu 18.04 上的 Postgres、Nginx 和 Gunicorn。

Django在创建项目时默认创建Wsgi文件。它存在于名称为 wsgi.py 的项目目录中。

您需要更改 systemctl 服务文件,以便它可以找到 wsgi 文件。

编辑

/etc/systemd/system/gunicorn.service

并将以下内容添加到[服务]部分

WorkingDirectory=/path/to/your/project