当我运行
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 2022-02-08 07:29:18 UTC; 17min ago
Main PID: 21841 (code=exited, status=217/USER)
Feb 08 07:29:18 ip-172-31-37-113 systemd[1]: Started gunicorn daemon.
Feb 08 07:29:18 ip-172-31-37-113 systemd[21841]: gunicorn.service: Failed to determine user credentials: No such process
Feb 08 07:29:18 ip-172-31-37-113 systemd[21841]: gunicorn.service: Failed at step USER spawning /home/ubuntu/bookclub/venv/bin/gun
Feb 08 07:29:18 ip-172-31-37-113 systemd[1]: gunicorn.service: Main process exited, code=exited, status=217/USER
Feb 08 07:29:18 ip-172-31-37-113 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
我正在按照 DigitalOcean 的 本教程 将我的 Django 网站转移到我的 EC2 实例上。我使用 Nginx 和 Gunicorn 以及 Django 来完成此任务。
这是我的
gunicorn.service
文件,位于 /etc/systemd/system/gunicorn.service
:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/ubuntu/bookclub
ExecStart=/home/ubuntu/bookclub/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/bookclub/books.sock books.wsgi:application
[Install]
WantedBy=multi-user.target
我用
books.sock
在我的项目文件夹中检查了 ls
,发现 books.sock
不存在。
我将 Gunicorn 服务文件中的
User
从 sammy
(不存在)更改为 ubuntu
(这是服务器上唯一存在的)。
所以我的
gunicorn.service
现在看起来像这样:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/ubuntu/bookclub
ExecStart=/home/ubuntu/bookclub/venv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/ubuntu/bookclub/books.sock books.wsgi:application
[Install]
WantedBy=multi-user.target
但是我收到另一个错误:
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2022-02-08 09:23:41 UTC; 19s ago
Main PID: 22533 (code=exited, status=203/EXEC)
Feb 08 09:23:41 ip-172-31-37-113 systemd[1]: Started gunicorn daemon.
Feb 08 09:23:41 ip-172-31-37-113 systemd[1]: gunicorn.service: Main process exited, code=exited, status=203/EXEC
Feb 08 09:23:41 ip-172-31-37-113 systemd[1]: gunicorn.service: Failed with result 'exit-code'.
您被误导了,因为在会话开始时需要遵循一个外部程序:初始服务器设置指南。
要做的事:
创建用户sammy
重要
usermod -aG sudo sammy
切换到 Sammy 个人资料
在 sammy 配置文件下创建 django 项目
pwd
/home/sammy
一切都会好起来的
原因? 1_可能这是数据库用户 2_可能根配置文件无效。 天知道。 祝你好运。