当我运行
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一起完成这个操作。
这是我位于/etc/systemd/system/gunicorn.service
的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
我使用ls
命令在我的项目文件夹中检查了books.sock
,发现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
吗?试着将User=ubuntu
放进去(我记得这是亚马逊 EC2 Ubuntu 的默认用户)。 - undefinedsystemctl status gunicorn
显示gunicorn
已经失败。我会编辑我的问题以包含这个信息。 - undefinedsudo chown ubuntu /home/ubuntu/bookclub/venv/bin/gunicorn
,看看是否有帮助。如果没有 - 还请提供journalctl --since="-1h"
的输出内容。 - undefined