首页 > 解决方案 > 无法使用套接字启动 gunicorn 服务

问题描述

我有一个 Django 和 Gunicorn 设置。如果我像这样从命令行启动 Gunicorn 服务:

gunicorn --bind 0.0.0.0:8000 first.wsgi

从以下工作目录:

~/code/firstdjangoproject/first

一切都按预期工作。

但是,当我尝试systemd使用以下gunicorn.service配置为 gunicorn 设置服务时:

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=pi
Group=www-data
WorkingDirectory=/home/pi/firstdjangoproject
ExecStart=/usr/local/bin/gunicorn \
          --access-logfile - \
          --error-logfile - /home/pi/error.log \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          first.wsgi:application

[Install]
WantedBy=multi-user.target

尝试使用以下方式访问该站点时出现以下错误curl --unix-socket /run/gunicorn.sock localhost

curl: (56) Recv failure: Connection reset by peer

当我查看日志时,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 Mon 2019-09-30 22:14:14 CEST; 7s ago
  Process: 3070 ExecStart=/usr/local/bin/gunicorn --access-logfile - --error-logfile - /home/pi/error.log --workers 3 --bind uni
 Main PID: 3070 (code=exited, status=210/CHROOT)

sep 30 22:14:14 raspberrypi systemd[1]: Started gunicorn daemon.
sep 30 22:14:14 raspberrypi systemd[1]: gunicorn.service: Main process exited, code=exited, status=210/CHROOT
sep 30 22:14:14 raspberrypi systemd[1]: gunicorn.service: Unit entered failed state.
sep 30 22:14:14 raspberrypi systemd[1]: gunicorn.service: Failed with result 'exit-code'.
sep 30 22:14:14 raspberrypi systemd[1]: gunicorn.service: Start request repeated too quickly.
sep 30 22:14:14 raspberrypi systemd[1]: Failed to start gunicorn daemon.
sep 30 22:14:14 raspberrypi systemd[1]: gunicorn.service: Failed with result 'exit-code'.

有人知道我在这里做错了什么吗?

标签: djangounixservicegunicornsystemd

解决方案


推荐阅读