【问题标题】:Bottle app on heroku with gunicorn - foreman works locally but not on heroku带有 gunicorn 的 heroku 上的瓶子应用程序 - 工头在本地工作,但不在 heroku 上
【发布时间】:2015-02-22 21:01:44
【问题描述】:

当我部署在 heroku 上时,我一直试图启动我的简单 bottle 应用程序。

经过相当多的搜索和修改,我得到了一个可以在本地运行的设置,但不能在 heroku 上运行。

/app.py:

import bottle
import beaker.middleware
from bottle import route, redirect, post, run, request, hook, template, static_file, default_app

bottle.debug(True)
app = beaker.middleware.SessionMiddleware(bottle.app(), session_opts)
...
# app routes etc, no run()

然后在/Procfile:

web: gunicorn app:app --bind="0.0.0.0:$PORT" --debug

如果我误解了 gunicorn 的工作原理,请纠正我,我将“app:app”部分理解为在名为 app.py 的模块(=文件)中查看并使用变量“app”中的任何内容作为您的 WSIG,是吗?

  • 我已经通过 $ heroku run bash 检查是否设置了 $PORT,似乎没问题
  • 我从其他 heroku 示例中获得的“0.0.0.0”IP,无论如何都应该接受任何 IP 服务器端,不是吗?
  • Python 依赖项似乎安装得很好
  • 我通过 .env 文件为工头设置了 $POST 变量,从而在本地运行,我的设置似乎一切正常
  • 基于this SO question 我检查了$ heroku ps

=== web (1X): `gunicorn app:app --bind="0.0.0.0:$PORT" --debug` web.1: crashed 2014/12/24 22:43:00 (~ 1m ago)*)

  • $ heroku logs 显示:

2014-12-24T20:42:59.235657+00:00 heroku[web.1]: Starting process with command `gunicorn app:app --bind="0.0.0.0:23177" --debug` 2014-12-24T20:43:00.434570+00:00 heroku[web.1]: State changed from starting to up 2014-12-24T20:43:01.813679+00:00 heroku[web.1]: State changed from up to crashed 2014-12-24T20:43:01.803122+00:00 heroku[web.1]: Process exited with status 3

我也不确定如何获得更好的调试结果。不知何故,Procfile 网络进程似乎无法正常工作/启动,但我如何才能获取有关什么问题的信息?

有人知道这里发生了什么吗?

P.S.:我对 heroku、python、bottle 和 gunicorn 比较陌生:O

【问题讨论】:

    标签: python heroku bottle gunicorn


    【解决方案1】:

    您使用什么版本的 gunicorn? gunicorn 19.1 默认不写错误日志。试试gunicorn --log-file=-

    -R 也是调查错误的有用选项。

    【讨论】:

    • 谢谢,试过了,虽然我找不到--log-file 的选项,但也许--access-logfile="-" 也一样?结果仍然相同,在本地工作,在应用程序崩溃的 heroku 上。
    • 没有。 --access-logfile 是访问日志。 --log-file 是错误日志。 gunicorn-docs.readthedocs.org/en/latest/settings.html#errorlog
    • 啊,做到了。得到错误跟踪,显然我在 .gitignore 上有一个模块错误(但在本地存在),这使得整个事情在 heroku 上崩溃并烧毁。当我检查文档时,我也没有看到命令别名,所以感谢您指出:)
    【解决方案2】:

    您可以尝试在您的 Procfile 中只使用 web: gunicorn app:app 而没有其他内容吗?

    【讨论】:

    • 感谢您的建议。试过了,它在heroku上不起作用,但在本地。正如预期的那样,我可能会添加,因为据我了解,heroku 动态提供应用程序应该监听的端口。
    • @kontur 有趣的是,我目前正在 heroku 上运行一个烧瓶应用程序,它仅适用于 Procfile...
    • 嗯,也许您的应用程序模块在启动时会以某种方式检索端口号?不过感谢您的建议,不幸的是,它似乎无法解决这个问题。
    猜你喜欢
    • 1970-01-01
    • 2021-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 2018-03-11
    相关资源
    最近更新 更多