【问题标题】:Port binding fails for script after 60 seconds when deployed to heroku部署到heroku 60 秒后脚本端口绑定失败
【发布时间】:2016-06-23 05:20:40
【问题描述】:

所以我在玩弄 slack API 并最终制作了一个简单的 slack 机器人,无论网站是否启动(当提供 URL 时)都会在 slack 频道上发布信息

每当我将它部署到 heroku 时,它会在前 60 秒内工作,然后在日志中抛出类似这样的错误

2016-06-22T20:18:11.933928+00:00 heroku[web.1]: State changed from crashed to starting
2016-06-22T20:18:15.635404+00:00 heroku[web.1]: Starting process with command `python margo/margo.py 5000`
2016-06-22T20:18:18.724727+00:00 app[web.1]: StarterBot connected and running!
2016-06-22T20:19:15.714485+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-06-22T20:19:15.714485+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2016-06-22T20:19:16.857081+00:00 heroku[web.1]: Process exited with status 137
2016-06-22T20:19:16.874584+00:00 heroku[web.1]: State changed from starting to crashed

我的Procfile 看起来像这样

web: python margo/margo.py 5000

我四处搜索,found thisthisPORT 应该在Profile 中指定,我像上面一样在Procfile 中更改了它。但我的只是一个简单的 python 脚本,而不是一个完整的 Flask/Django 应用程序。

各位有什么想法吗?

编辑

我读到$PORT 环境变量是由heroku 设置的。所以我的Procfile 现在是

web: python margo/margo.py $PORT

但程序在部署时再次崩溃并显示相同的错误消息

【问题讨论】:

    标签: python heroku deployment


    【解决方案1】:

    我通过在 Heroku 提供的端口上运行一个简单的 HTTP 服务器并使其作为后台进程运行来解决了这个问题。

    更改后,我的Procfile 是这样的

    web: (python -m http.server $PORT &) && (python margo/margo.py)
    

    因此,即使 Web 服务器什么都不做,它也会将自己绑定到端口并防止应用程序进一步崩溃。

    【讨论】:

    • 而不是&& 构造,我建议使用单独的流程线:worker: python margo/margo.py。然后您可以通过heroku ps:start worker 显式管理它。
    猜你喜欢
    • 2020-01-02
    • 2017-06-03
    • 1970-01-01
    • 2014-11-07
    • 1970-01-01
    • 2021-11-14
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多