确保加载 Rails 应用程序时某些进程正在运行

发布于 2024-10-19 14:42:12 字数 168 浏览 2 评论 0原文

我想确保当我的 Rails 3 应用程序初始化或加载时,某些进程(例如 Sunspot Solr search 和 Delayed_job)正在运行。

我有点菜鸟,据我所知,我可以编写一个自定义初始化程序或使用像 God 或 Monit 这样的进程监视框架。

有人可以建议这里的最佳路径吗?

I want to ensure that certain processes like Sunspot Solr search and delayed_job are running when my Rails 3 app initializes or loads.

I'm somewhat of a noob and from what I can tell, I could write a custom initializer or use a process monitoring framework like God or Monit.

Can someone please suggest the optimal path to take here?

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

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

发布评论

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

评论(3

撩发小公举 2024-10-26 14:42:12

如果您正在运行 Rails 应用程序,God 是一个非常好的选择。如果您不熟悉,Railscasts 有一个很好的截屏视频可以帮助您入门:

http://railscasts。 com/episodes/130-monitoring-with-god

If you are running a Rails application God is a very good option. If you are unfamiliar, Railscasts has a good screencast to get you started:

http://railscasts.com/episodes/130-monitoring-with-god

疯了 2024-10-26 14:42:12

您可以编写一个初始值设定项来检查,例如

raise ProcessNotRunning::MyProcess if `ps aux | grep 'processname' | grep -v grep | wc -l`.strip.zero?

You could write an initializer that checks, something like

raise ProcessNotRunning::MyProcess if `ps aux | grep 'processname' | grep -v grep | wc -l`.strip.zero?
最后的乘客 2024-10-26 14:42:12

初始化方法的问题在于,即使所有必需的进程都在启动时运行,也不能保证它们在应用程序运行的接下来几周或几个月内继续运行

使用监控框架——God 和 Monit 都是很好的解决方案——你可以确定,即使你的某个进程死掉了,它也会自动重新启动。此外,您还可以在发生这种情况时收到通知,以便在问题开始发生时尽早收到通知。

简而言之:与任何自制解决方案相比,监控框架很可能是更好的解决方案。

The problem with the initializer approach is that even if all your required processes are running at startup, there's is no guarantee they keep running the next few weeks or months your application is running.

Using a monitoring framework - both God and Monit are good solutions - you can be sure that even if one of your processes dies, it'll be restarted automatically. Also you can be notified when that happens, so you get notified early when problems are starting to happen.

In a nutshell: A monitoring framework will most likely be the better solution compared to any home-brewn solution.

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