将 Ruby/EventMachine 脚本作为系统服务运行

发布于 2024-10-09 04:19:16 字数 109 浏览 0 评论 0 原文

我使用 EventMachine 用 Ruby 编写了一个简单的 UDP 服务器。我想让它始终在我的 Linux 机器上运行。关于如何将其包装为系统服务或以其他形式在启动时启动、保持运行、可以监控的建议?

I've written a simple UDP server in Ruby using EventMachine. I'd like to keep it always running on my Linux box. Suggestions on how to wrap it up as a system service or in some other form that launches at start-up, stays running, can be monitored?

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

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

发布评论

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

评论(4

左岸枫 2024-10-16 04:19:16

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.

梦境 2024-10-16 04:19:16

我会将 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

云淡风轻 2024-10-16 04:19:16

所有这些答案都已经过时了。 Ruby 有完美的 Process.daemon 方法:http://www.ruby-doc.org/core-2.1.0/Process.html#method-c-daemon

只需在您的应用程序中添加 Process.daemonEM.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-daemon

Just add Process.daemon in your application before EM.run and all should work.

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