简体   繁体   English

Gunicorn主管启动错误

[英]Gunicorn Supervisor Startup Error

I've followed this tutorial twice, but on the second machine that I've run it on I get a supervisor-run gunicorn error. 我已经两次阅读本教程 ,但是在运行它的第二台机器上却遇到了由管理员运行的gunicorn错误。 When I tell supervisor to startup gunicorn using: 当我告诉主管使用以下方法启动gunicorn时:

$ sudo supervisorctl start gunicorn
gunicorn: ERROR (abnormal termination)

The gunicorn_err.log repeats this: gunicorn_err.log重复此步骤:

Unknown command: 'run_gunicorn'
Type 'manage.py help' for usage.

The supervisor config looks like: 主管配置如下所示:

[program:gunicorn]
command=/home/ubuntu/.virtualenvs/<VIRTUALENV>/bin/python /home/ubuntu/<APPNAME>/manage.py run_gunicorn -w 4 -k gevent
directory=/home/ubuntu/<APPNAME>
user=www-data
autostart=true
autorestart=true
stdout_logfile = /var/log/supervisor/gunicorn.log
stderr_logfile = /var/log/supervisor/gunicorn_err.log

The gunicorn.log is empty. gunicorn.log为空。 I've tried changing the user to ubuntu and running without a virtualenv (my 'default' python environment is also ready to go as in it has all pre-requisite packages.) I have even tried removing spaces between the variable assignments in gunicorn.conf Actually if I manually run: 我尝试将用户更改为ubuntu并在没有virtualenv的情况下运行(我的“默认” python环境也已准备就绪,因为它具有所有必备软件包。)我甚至尝试过删除gunicorn中变量分配之间的空格。 conf实际上,如果我手动运行:

$ /usr/bin/python /home/ubuntu/<APPNAME>/manage.py run_gunicorn -w 4 -k gevent
2013-01-22 19:20:33 [1231] [INFO] Starting gunicorn 0.17.2
2013-01-22 19:20:33 [1231] [INFO] Listening at: http://127.0.0.1:8000 (1231)
2013-01-22 19:20:33 [1231] [INFO] Using worker: gevent
2013-01-22 19:20:33 [1236] [INFO] Booting worker with pid: 1236
2013-01-22 19:20:33 [1237] [INFO] Booting worker with pid: 1237
2013-01-22 19:20:33 [1238] [INFO] Booting worker with pid: 1238
2013-01-22 19:20:33 [1239] [INFO] Booting worker with pid: 1239

And same with the virtualenv python run: 与virtualenv python运行相同:

$ /home/ubuntu/.virtualenvs/<VIRTUALENV>/bin/python /home/ubuntu/<APPNAME>/manage.py run_gunicorn -w 4 -k gevent
2013-01-22 19:21:53 [1246] [INFO] Starting gunicorn 0.17.2
2013-01-22 19:21:53 [1246] [INFO] Listening at: http://127.0.0.1:8000 (1246)
2013-01-22 19:21:53 [1246] [INFO] Using worker: gevent
2013-01-22 19:21:53 [1251] [INFO] Booting worker with pid: 1251
2013-01-22 19:21:53 [1252] [INFO] Booting worker with pid: 1252
2013-01-22 19:21:53 [1253] [INFO] Booting worker with pid: 1253
2013-01-22 19:21:53 [1254] [INFO] Booting worker with pid: 1254

How is it possible that the supervisor initiated gunicorn is unable to find the 'run_gunicorn' command when I can run it using any python environment and it works? 当我可以使用任何python环境运行它时,主管启动的gunicorn怎么可能找不到'run_gunicorn'命令? And yes 'gunicorn' , is in the INSTALLED_APPS 是的, 'gunicorn'位于INSTALLED_APPS

Turns out it was an environmental variable that I was getting in settings.py that didn't exist under supervisord's start gunicorn. 原来,这是我进入settings.py中的一个环境变量,在主管的启动条件下不存在。

In addition, the environmental variable error was being suppressed and never made it to the gunicorn_err.log 此外,环境变量错误得到了抑制,并且从未出现在gunicorn_err.log中

When I switched the gunicorn.conf command to : 当我将gunicorn.conf命令切换为时:

command = /usr/local/bin/gunicorn_django -w 4 -k gevent

I could see a clearer error in gunicorn_err.log 我可以在gunicorn_err.log中看到更清晰的错误

    raise KeyError(key)
KeyError: 'AWS_STORAGE_BUCKET_NAME'
2013-01-22 22:51:09 [2290] [INFO] Worker exiting (pid: 2290)

To address this I just didn't use an environmental variable got the variable using a different means. 为了解决这个问题,我只是没有使用环境变量,而是使用了不同的方法来获取变量。 It worked then an I reverted back to the original virtualenv run_gunicorn command 它起作用了,然后我又恢复为原来的virtualenv run_gunicorn命令

command=/home/ubuntu/.virtualenvs/<VIRTUALENV>/bin/python /home/ubuntu/<APPNAME>/manage.py run_gunicorn -w 4 -k gevent

If continuing to use environmental variables in settings is important, take a look at supervisord-configuration there seems to be a way to configure key/value environment variable pairs for supervisord executed applications. 如果继续在设置中使用环境变量很重要,请看一下监督配置 ,似乎有一种方法可以为监督执行的应用程序配置键/值环境变量对。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM