如何在没有WSGI的情况下为Gunicorn配置ExecStart



Systemd 和 Gunicorn 需要某种 wsgi 文件作为最后一个要ExecStart的参数: http://docs.gunicorn.org/en/latest/deploy.html?highlight=ExecStart#systemd

对于 Django,这在主模块中为 wsgi.py

ExecStart=/home/admin/django/bin/gunicorn --config /home/admin/src/gunicorn.py --bind unix:/tmp/api.sock myapp.wsgi

但是在使用 Sanic 和 uvloop 时,这个文件显然不存在(我相信新协议称为 ASGI(。我尝试用它代替app.py不出所料

地不起作用:
ExecStart=/home/admin/sanic/bin/gunicorn --config /home/admin/src/gunicorn.py --bind unix:/tmp/api.sock myapp.app

使用Sanic时应如何配置此参数?

如果你想用systemd开始sanic,为什么不使用supervisrod:Supervisord。

引导 -> 系统d -> 主管 -> 枪角兽 -> sanic

[unix_http_server]
file=/tmp/supervisor.sock                       ; path to your socket file
[supervisord]
logfile=/var/log/supervisord/supervisord.log    ; supervisord log file
logfile_maxbytes=50MB                           ; maximum size of logfile before rotation
logfile_backups=10                              ; number of backed up logfiles
loglevel=error                                  ; info, debug, warn, trace
pidfile=/var/run/supervisord.pid                ; pidfile location
nodaemon=false                                  ; run supervisord as a daemon
minfds=1024                                     ; number of startup file descriptors
minprocs=200                                    ; number of process descriptors
user=root                                       ; default user
childlogdir=/var/log/supervisord/               ; where child log files will live
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock         ; use a unix:// URL  for a unix socket
[program:ctrlapi]
directory=/home/ubuntu/api
command=/home/ubuntu/api/venv3/bin/gunicorn api:app --bind 0.0.0.0:8000 --worker-class sanic.worker.GunicornWorker -w 2
stderr_logfile = log/api_stderr.log
stdout_logfile = log/api_stdout.log

我还没有用 Systend 和 gunicorn 部署它。但是,文档似乎在这方面非常好。

为了使用 Gunicorn

运行 Sanic 应用程序,您需要使用特殊的 sanic.worker.GunicornWorker for Gunicorn worker-class 参数:

gunicorn myapp:app --bind 0.0.0.0:1337 --worker-class sanic.worker.GunicornWorker

考虑到这一点,这个怎么样:

ExecStart=/home/admin/sanic/bin/gunicorn --config /home/admin/src/gunicorn.py myapp:app --bind 0.0.0.0:1337 --worker-class sanic.worker.GunicornWorker

我认为你缺少的一大块是GunicornWorker工人阶级。

相关内容

最新更新