【发布时间】:2019-09-03 03:56:40
【问题描述】:
我正在使用 Django 和 Django-Channels 部署一个网站,其中 Channel 的 daphne ASGI 服务器代替了典型的 Gunicorn WSGI 设置。使用this Gunicorn WSGI tutorial 作为入门指南,我尝试为我的 daphne 服务器编写一个 systemctl 服务,但遇到以下错误:
CRITICAL Listen failure: [Errno 13] Permission denied: '27646' -> b'/run/daphne.sock.lock'
不幸的是,我无法找到任何答案来解释为什么.sock 文件的权限会被拒绝(在 Daphne 的上下文中),所以我希望我能得到一些关于从哪里开始调试这个问题的提示。以下是我的daphne.socket 和我的daphne.service 文件。
daphne.service
[Unit]
Description=daphne daemon
Requires=daphne.socket
After=network.target
[Service]
User=brianl
Group=www-data
WorkingDirectory=/home/brianl/autoXMD
ExecStart=/home/brianl/autoXMD/env/bin/daphne -u /run/daphne.sock -b 0.0.0.0 -p 8000 autoXMD.asgi:application
[Install]
WantedBy=multi-user.target
daphne.socket
[Unit]
Description=daphne socket
[Socket]
ListenStream=/run/daphne.sock
[Install]
WantedBy=sockets.target
根据链接的 DigitalOcean 教程,我使用 sudo systemctl start daphne.socket 开始我的服务。
我的猜测是,我错过了为 Gunicorn 和 Daphne 设置 systemctl 服务之间存在某种差异,但我不确定。
(如果有帮助,我打算使用 Nginx 作为主服务器,但我还没有达到那个点)
编辑:
如果我还附上 systemd 给出的完整输出,那会有所帮助:
● daphne.service - daphne daemon
Loaded: loaded (/etc/systemd/system/daphne.service; enabled; vendor preset: enabled)
Active: failed (Result: start-limit-hit) since Thu 2019-09-05 22:00:43 UTC; 1min 51s ago
Process: 22041 ExecStart=/home/brianl/autoXMD/env/bin/daphne -u /run/daphne.sock -b 0.0.0.0 -p 8000 autoXMD.asgi:application (code=exited, status=0/SUCCESS)
Main PID: 22041 (code=exited, status=0/SUCCESS)
Sep 05 22:00:43 autoxmd daphne[22041]: warnings.warn('%s. joblib will operate in serial mode' % (e,))
Sep 05 22:00:43 autoxmd daphne[22041]: 2019-09-05 22:00:43,013 INFO Starting server at tcp:port=8000:interface=0.0.0.0, unix:/run/daphne.sock
Sep 05 22:00:43 autoxmd daphne[22041]: 2019-09-05 22:00:43,017 INFO HTTP/2 support not enabled (install the http2 and tls Twisted extras)
Sep 05 22:00:43 autoxmd daphne[22041]: 2019-09-05 22:00:43,020 INFO Configuring endpoint tcp:port=8000:interface=0.0.0.0
Sep 05 22:00:43 autoxmd daphne[22041]: 2019-09-05 22:00:43,022 INFO Listening on TCP address 0.0.0.0:8000
Sep 05 22:00:43 autoxmd daphne[22041]: 2019-09-05 22:00:43,022 INFO Configuring endpoint unix:/run/daphne.sock
Sep 05 22:00:43 autoxmd daphne[22041]: 2019-09-05 22:00:43,022 CRITICAL Listen failure: [Errno 13] Permission denied: '22041' -> b'/run/daphne.sock.lock'
Sep 05 22:00:43 autoxmd systemd[1]: daphne.service: Start request repeated too quickly.
Sep 05 22:00:43 autoxmd systemd[1]: daphne.service: Failed with result 'start-limit-hit'.
Sep 05 22:00:43 autoxmd systemd[1]: Failed to start daphne daemon.
【问题讨论】:
-
您为用户
brianl更改文件夹/run的所有者了吗? -
正如@ToanQuocHo 提到的那样,因为
brianl用户没有在.sock上写字的权限。你可以使用sudo chmod 775 .sock -
嘿,我尝试了
sudo chmod 775 /run(和sudo chmod 775 /run/*),但都没有成功。还有其他建议吗? -
好的,我明白了。您的配置中有错误。问题是,这个
daphne -u /run/daphne.sock -b 0.0.0.0 -p 8000不等同于gunicorn -bind ....daphne-u的参数将尝试创建unix 套接字然后绑定到它。解决方案是通过自己创建套接字来省略部分。所以只需从服务中删除Requires=daphne.socket。 -
编辑:似乎另外删除
-u /run/daphne.sock最终使curl工作。我将如何使用套接字方法使其工作? (给以后遇到这个问题的人)
标签: django django-channels daphne