与 Rails 初始值设定项 (2.xx) 相反?

发布于 2024-09-10 11:22:42 字数 111 浏览 4 评论 0 原文

当我启动 Rails 应用程序时,我在 config/initializers/ 中运行多个守护进程,但我需要一种方法来检测应用程序何时关闭并停止守护进程。

有什么钩子/地方可以做到这一点吗?

I run several daemons in config/initializers/ when I start my rails app, but I need a way to detect when the app is shutting down, and stop the daemons.

Are there any hooks / places where I can do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春风十里 2024-09-17 11:22:42

据我所知,没有正式的方法可以在 Rails 框架内展开应用程序。您可以考虑为基本 Ruby at_exit 语言安装一个或多个处理程序设施。然而,这只适用于应用程序的有序关闭。

更通用的策略是使用服务器监视框架,该框架可以捕获应用程序的有序和意外退出情况。我非常怀疑如果您的 Rails 实例托管在 Passengerat_exit 处理程序会被调用a> 以及相关的 Apache 或 Nginx 服务器由于某种原因崩溃了,尽管我没有实际测试过。类似的观察可能适用于任何意外退出的应用程序容器。

您可以考虑类似 GodMonitNagios (取决于您的要求的复杂程度)用于实施处理应用程序关闭的一般策略并针对每种情况执行正确的操作。这些框架也可以监视这些守护进程。

There's no formal way to unwind an application within the Rails framework as far as I know. You could consider installing one or more handlers for the basic Ruby at_exit language facility. However this is only going to deal with an ordered shutdown of the application.

A more general strategy would be to use a server monitoring framework which would catch the ordered and unexpected exit cases for your application. I doubt very much that at_exit handlers would be called if your rails instance was hosted inside Passenger and the associated Apache or Nginx server crashed for some reason although I've not actually tested this. Similar observations would likely apply for any application container that would exit unexpectedly.

You could consider something like God or Monit or Nagios (depending on how sophisticated your requirements) for implementing a general strategy for handing application shutdown and doing the right thing for each set of circumstances. These frameworks can also monitor those daemons too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文