【问题标题】:Gunicorn Supervisor Startup ErrorGunicorn Supervisor 启动错误
【发布时间】:2013-01-06 00:52:06
【问题描述】:

我已经关注this tutorial 两次,但是在我运行它的第二台机器上,我得到了一个主管运行的 gunicorn 错误。当我告诉主管启动 gunicorn 时使用:

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

gunicorn_err.log 重复这个:

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

主管配置如下:

[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

gunicorn.log 为空。我尝试将用户更改为 ubuntu 并在没有 virtualenv 的情况下运行(我的“默认”python 环境也已准备就绪,因为它具有所有先决条件包。)我什至尝试在 gunicorn 中删除变量分配之间的空格。会议 其实如果我手动运行:

$ /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

与 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

当我可以使用任何 python 环境运行它并且它可以工作时,主管启动的 gunicorn 怎么可能找不到“run_gunicorn”命令?是的'gunicorn',在INSTALLED_APPS

【问题讨论】:

    标签: django gunicorn supervisord


    【解决方案1】:

    原来它是我在 settings.py 中得到的一个环境变量,在 supervisord 的 start gunicorn 下不存在。

    此外,环境变量错误被抑制并且从未进入gunicorn_err.log

    当我将 gunicorn.conf 命令切换为:

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

    我可以在 gunicorn_err.log 中看到更清晰的错误

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

    为了解决这个问题,我只是没有使用环境变量,而是使用不同的方式获取了变量。然后它起作用了,我恢复到原来的 virtualenv run_gunicorn 命令

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

    如果在设置中继续使用环境变量很重要,请查看supervisord-configuration,似乎有一种方法可以为 supervisord 执行的应用程序配置键/值环境变量对。

    【讨论】:

      猜你喜欢
      • 2015-04-21
      • 2012-11-22
      • 2013-10-05
      • 2014-03-31
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 2013-12-08
      • 1970-01-01
      相关资源
      最近更新 更多