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

2024-05-08

Systemd 和 Gunicorn 需要某种 wsgi 文件作为最后一个参数ExecStart: http://docs.gunicorn.org/en/latest/deploy.html?highlight=ExecStart#systemd 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:主管 http://supervisord.org/.

启动 -> 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在没有 WSGI 的情况下为 Gunicorn 配置 ExecStart? 的相关文章

随机推荐