Rails 在生产 Passenger 中不断重新启动
我正在运行一个应用程序,该应用程序在初始化程序中启动 Rufus Scheduler 进程。该应用程序在生产中与 Passenger 一起运行,我注意到一些奇怪的行为:
首先,为了重新启动服务器并确保初始化程序运行,您必须 touch tmp/restart.txt
并在浏览器中加载应用程序。此时,初始化器将被触发。可怕的是,如果您只进行触摸,Rufus 安排的进程将被重置,并且不会重新安排,直到您在浏览器中加载应用程序。
仅此一点我就能应付。但这导致了第二个问题:我会注意到计划的进程尚未运行,因此我加载了一个页面,突然日志文件告诉我它正在运行初始化程序,就像我重新启动一样。因此,在某些时候,Passenger 会随机重新启动,就好像我触摸了 tmp/restart.txt 并清除了我的预定进程一样。
我对 Passenger 和 Rails 的集成知之甚少,所以我不知道这种偶尔的重启是否是异常的,还是架构的全部部分。任何人都可以针对这种情况提供任何智慧吗?
I'm running an application that kicks off a Rufus Scheduler process in an initializer. The application is running with Passenger in production and I've noticed a couple weird behaviors:
First, in order to restart the server and make sure the initializer gets run, you have to both touch tmp/restart.txt
and load the app in a browser. At that point, the initializer fires. The horrible thing is that if you only do the touch, the processes scheduled by Rufus get reset and aren't rescheduled until you load the app in a browser.
This alone I can deal with. But this leads to the second problem: I'll notice that the scheduled process hasn't run, so I load a page and suddenly the log file is telling me that it's running the initializers as if I'd rebooted. So, at some point, Passenger is randomly rebooting as if I'd touched tmp/restart.txt and wiping out my scheduled processes.
I have an incredibly poor understanding of Passenger and Rails's integration, so I don't know whether this occasional rebooting is aberrant or all part of the architecture. Can anyone offer any wisdom on this situation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您所描述的是 Passenger 的工作方式。当流量需要时,它会生成应用程序的新实例,并在不活动一段时间后关闭它们以释放资源。
您应该阅读 Passenger 文档,特别是资源控制和优化部分 。如果您想要的话,有些设置可以防止应用程序被 Passenger 关闭。
使用 PassengerPoolIdleTime 设置,您可以保持至少一个进程运行,但您几乎肯定希望 Passenger 根据需要启动应用程序的其他实例。 Rufus 上的此帖子调度程序 Google Group 提到使用锁定文件来防止多个进程启动调度程序,这可能对您有用。
What you describe is the way Passenger works. It spawns new instances of the application when traffic warrants them, and shuts them down after periods of inactivity to free resources.
You should read the Passenger documentation, particularly the Resource Control and Optimization section. There are settings which can prevent the application from being shut down by Passenger, if that is what you want.
Using the PassengerPoolIdleTime setting, you could keep at least one process running, but you'll almost certainly want Passenger to start up other instances of the app as necessary. This thread on the Rufus Scheduler Google Group mentions using lock files to prevent more than one process from starting the scheduler, that may be useful to you.