主管gunicorn flask错误

时间:2016-10-31 10:07:05

标签: flask gunicorn supervisor

我已经使用gunicorn部署我的烧瓶应用程序,当我使用gunicorn启动我的烧瓶应用程序时,它工作正常。当我改为使用主管观看gunicorn时,我可以访问我的网站,但是主管提供这些日志:

2016-10-31 17:49:49,967 INFO supervisord started with pid 32949
2016-10-31 17:49:50,970 INFO spawned: 'vservice' with pid 32952
2016-10-31 17:49:51,971 INFO success: vservice entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2016-10-31 17:49:56,285 INFO exited: vservice (exit status 1; not expected)
2016-10-31 17:49:57,287 INFO spawned: 'vservice' with pid 32955
2016-10-31 17:49:58,289 INFO success: vservice entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2016-10-31 17:50:02,605 INFO exited: vservice (exit status 1; not expected)
2016-10-31 17:50:03,608 INFO spawned: 'vservice' with pid 32960
2016-10-31 17:50:04,609 INFO success: vservice entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2016-10-31 17:50:08,924 INFO exited: vservice (exit status 1; not expected)
2016-10-31 17:50:09,926 INFO spawned: 'vservice' with pid 32965
2016-10-31 17:50:10,927 INFO success: vservice entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

和主管stderrlog是这样的:

Error: Already running on PID 30874 (or pid file 'log/gunicorn.pid' is stale)

这是我的gunicorn配置文件:

import gevent.monkey
import multiprocessing

gevent.monkey.patch_all()

bind = '0.0.0.0:9000'

loglevel = 'error'
logfile = 'log/debug.log'
accesslog = 'log/access.log'
access_log_format = '%(h)s %(t)s %(U)s %(q)s'
errorlog = 'log/error.log'

pidfile = 'log/gunicorn.pid'

# number of processes
workers = multiprocessing.cpu_count() * 2 + 1
# number of threads of per process
threads = multiprocessing.cpu_count() * 2
worker_class = 'gevent'

这是我的主管配置文件:

[program:vservice]
command=/data/server/venv/bin/gunicorn -c /data/server/gun.py manager:app
directory=/data/server/
stdout_logfile=/data/supervisor/log/stdout.log
stderr_logfile=/data/supervisor/log/stderr.log

当我使用gunicorn -c gun.py manager:app时,我的应用程序工作正常,但当我使用主管运行它时,它会出现如上所述的错误,我仍然可以访问我的网站,这似乎是我的应用程序有效,但主管给出的错误是什么意思?它对我的部署有什么不良影响吗?

感谢。

1 个答案:

答案 0 :(得分:0)

我从这里得到了一个想法。 https://github.com/benoitc/gunicorn/issues/520#issuecomment-236301509

尝试使用bash脚本来运行gunicorn。您的超级用户配置文件应如下所示:

[program:vservice]
command=/path-to-bash-script/gunicorn.sh
directory=/data/server/
stdout_logfile=/data/supervisor/log/stdout.log
stderr_logfile=/data/supervisor/log/stderr.log

设置gunicorn.sh以运行gunicorn应用程序的exec命令

#!/bin/sh
exec /data/server/venv/bin/gunicorn -c /data/server/gun.py manager:app

从你的gunicorn配置文件中删除行pidfile = 'log/gunicorn.pid'

这是因为你的bash脚本是受到监督的,而不是枪手。