【问题标题】:CloudFoundry destroyes instance right after start but not shutting down fullyCloudFoundry 在启动后立即销毁实例但未完全关闭
【发布时间】:2020-07-09 08:36:12
【问题描述】:

我在使用 CloudFoundry 方面并没有真正的经验。我知道如何使用它来将服务连接到应用程序,以及推送战争、日志文件等。所以标准的东西。 但是当谈到 CloudFoundry 的配置和行为时,我的知识就结束了。

我的问题是,在我的应用程序启动并且 New Relic 完成后,它正在记录它用作收集器的内容等。CloudFoundry Cell 正在停止实例。 我使用 spring 集成,因为关闭 jvm 的信号而关闭了所有东西。 我还为某些作业禁用了数据库中的几个布尔值。 到目前为止,一切正常,一切正常。

一旦关闭所有内容,CloudFoundry 就会开始销毁当前实例的容器。之后日志条目说销毁成功。 但应用程序仍在运行以及实例。 我的应用程序仍然在这里不时记录一些东西(不是关闭的作业),并且该实例似乎仍然存在并且没有被“更新”。

有人知道为什么会这样吗?我是否必须在 spring 中实现一些阻止实例被破坏的东西?或者这是我需要进行的 CloudFoundry 配置?

一个奇怪的事情是,它只发生一次同行周。每个星期三晚上到星期四早上。几乎在同一时间。

编辑: 这是我删除所有敏感信息的日志

   Some logs which indicate that the app is still running as expected.
   
   // I think this is the part where i gets interesting.
   2020-07-09T00:44:09.87+0200 [CELL/0] OUT Cell XXX requesting replacement for instance XXX
   2020-07-09T00:44:10.37+0200 [CELL/0] OUT Cell XXX creating container for instance XXX
   2020-07-09T00:44:12.17+0200 [CELL/0] OUT Cell XXX successfully created container for instance XXX
   
   Downloading droplet, starting the application and notice that it was shutted down unexpectedly. The indication for that is a flag in the database that hasn't been set to true which would happen during a proper shutdown.
   
   2020-07-09T00:45:14.70+0200 [CELL/0] OUT Container became healthy
   
   Some New Relic information which are not important for this question.
   
   2020-07-09T00:45:19.94+0200 [CELL/0] OUT Cell XXX stopping instance XXX
   
   This is the part where the application shuts down it's listeners and jobs.
   
   2020-07-09T00:45:25.70+0200 [APP/PROC/WEB/0] OUT Exit status 143
   2020-07-09T00:45:25.70+0200 [CELL/0] OUT Cell XXX destroying container for instance XXX
   2020-07-09T00:45:25.88+0200 [PROXY/0] OUT Exit status 137
   2020-07-09T00:45:26.07+0200 [CELL/0] OUT Cell XXX successfully destroyed container for instance XXX
   2020-07-09T00:49:36.17+0200 [APP/PROC/WEB/0] OUT 2020-07-09T00:49:36,178+0200 Some log entry which indicates that the app is still alive

完成后,应用程序仍在运行(中间没有重新启动),可以通过将标志设置为 true 再次启动所有作业,该标志在关闭挂钩的代码中设置为 false,因此没有新作业将在应用关闭时启动。

【问题讨论】:

  • 您能显示您的cf logs、清单和cf app 输出吗?您使用的是蓝绿部署吗?
  • @jAC 我编辑了问题并添加了我怀疑的日志,但没有回答如何解决它,如果我的怀疑是真的。

标签: java spring cloud spring-integration cloud-foundry


【解决方案1】:

我现在知道问题所在了。感谢一位同事,当他看到日志时,他确切地知道发生了什么。

CloudFoundry 在销毁旧实例之前创建一个新实例以避免停机。 一旦新实例启动并且健康,它就会破坏旧实例。 在新实例上运行的应用程序仍然接收到旧实例的关闭信号并执行关闭钩子中的代码。这意味着标志将设置为 false 以在应用关闭时停止所有作业。

为避免这种情况,使用实例 ID 很重要。每个作业都需要获取它运行的实例的 id。随着新实例的启动,必须​​在作业表中覆盖实例 ID。所以作业在新实例而不是旧实例上运行。

【讨论】:

    猜你喜欢
    • 2016-09-19
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 2015-08-22
    • 2022-11-13
    • 1970-01-01
    相关资源
    最近更新 更多