如何配置不使用WSGI的Gunicorn的ExecStart?

3

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 时,应该如何配置此参数?
2个回答

1
如果您想使用systemd启动sanic,为什么不使用supervisrod: Supervisord
引导 -> Systemd -> supervisord -> gunicorn -> 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

抱歉,我忘了,在systemd方面,您需要执行supervisord -c supervisord.conf,这是上面提到的配置文件。 - Christo Goosen

0

我自己还没有使用Systend和gunicorn部署过这个程序。但是,文档看起来对此很好。

为了使用Gunicorn运行Sanic应用程序,您需要使用特殊的sanic.worker.GunicornWorker作为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 工作类。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接