将 Ruby/EventMachine 脚本作为系统服务运行
我使用 EventMachine 用 Ruby 编写了一个简单的 UDP 服务器。我想让它始终在我的 Linux 机器上运行。关于如何将其包装为系统服务或以其他形式在启动时启动、保持运行、可以监控的建议?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当你在 Linux 上时,你可以使用 daemons gem
http://daemons.rubyforge.org/< /a>
http://railscasts.com/episodes/129-custom-daemon
As you are on linux you can use daemons gem
http://daemons.rubyforge.org/
http://railscasts.com/episodes/129-custom-daemon
Thin 网络服务器构建在 EventMachine 之上,使用 守护进程 gem: https://github.com/macournoyer/thin/blob/master/lib/thin/daemonizing.rb
要保持其运行,请使用 Monit,可以配置它来检查进程是否正在运行,如果没有运行则重新启动它,或者如果它开始使用太多系统资源或无休止的数组则重新启动其他可能的条件。
The Thin webserver, which is built on top of EventMachine, uses the daemons gem: https://github.com/macournoyer/thin/blob/master/lib/thin/daemonizing.rb
To keep it running, use Monit, which can be configured to check that the process is running, restart it if it's not, or restart if it starts using too much system resources, or an endless array of other possible conditions.
我会将 Cron 与 [@restart][1] 一起使用。一个行为良好的守护进程应该在再次运行之前检查它是否已经在运行。
[1]:https://help.ubuntu.com/community/CronHowto#Advanced定时任务
I would use Cron with [@restart][1]. A well behaved daemon should check if its already running before running again.
[1]: https://help.ubuntu.com/community/CronHowto#Advanced Crontab
所有这些答案都已经过时了。 Ruby 有完美的
Process.daemon
方法:http://www.ruby-doc.org/core-2.1.0/Process.html#method-c-daemon只需在您的应用程序中添加
Process.daemon
在EM.run
之前,一切都应该有效。All these answers are outdated. Ruby has perfect
Process.daemon
method: http://www.ruby-doc.org/core-2.1.0/Process.html#method-c-daemonJust add
Process.daemon
in your application beforeEM.run
and all should work.