[英]Start Ruby on Rails app through systemd socket activation (i.e. start Rails server listening on pre-existing socket)
As the title states, I'm trying to start a Ruby on Rails app through systemd socket activation. 如标题所示,我正在尝试通过systemd套接字激活来启动Ruby on Rails应用。 I've no prior experience with Ruby and the lack of quality documentation is frustrating.
我以前没有使用Ruby的经验,并且缺乏质量文档令人沮丧。
Obtaining the listen socket from systemd is trivial enough, though I'm struggling to put that socket to use. 从systemd获得listen套接字很简单,尽管我正在努力使用该套接字。 Is there an app server, that accepts a pre-existing listen socket?
是否有一个接受预先存在的侦听套接字的应用服务器? Or do I have to write my own, possibly by implementing a Rack::Handler (going by what limited information I've been able to gather from the documentation)?
还是我必须写一个自己的,可能是通过实现一个Rack :: Handler(根据我能够从文档中收集到的有限信息来完成)? In the latter case a minimal example implementation would be helpful.
在后一种情况下,最少的示例实现会有所帮助。
I'm looking for a production-suitable, lightweight, least-effort solution, capable of serving an average of 2 concurrent users on embedded hardware. 我正在寻找一种适合生产,轻便,省力的解决方案,该解决方案能够平均为2位嵌入式硬件上的并发用户提供服务。
Starting with Puma 3.0.0, socket activation is supported by its Rack module, which is used by rails server
. 从Puma 3.0.0开始,其Rack模块支持套接字激活,该模块由
rails server
。 This means that running bin/rails server puma
from systemd with socket activation will now work out of the box (tested with Puma 3.9.1). 这意味着通过套接字激活从systemd运行
bin/rails server puma
现在将立即可用(已通过Puma 3.9.1测试)。 One caveat is that you must start bin/rails
inside your application root, not the globally installed version. 一个警告是您必须在应用程序根目录(而不是全局安装的版本)中启动
bin/rails
。
For more details on this setup and some examples, see my blogpost . 有关此设置的更多详细信息和一些示例,请参阅我的博客文章 。
In absence of any alternatives, I'll likely end up using the Puma web server, which implements the systemd socket activation protocol . 在没有其他选择的情况下,我可能最终会使用Puma Web服务器,
该服务器实现了systemd套接字激活协议 。
EDIT: Puma does implement socket activation, but not in the Rack handler. 编辑:Puma确实实现了套接字激活,但是没有在Rack处理程序中实现。 I arrived at my initial conclusion via
grep -r LISTEN_FDS
and only discovered my mistake once I actually tried it. 我通过
grep -r LISTEN_FDS
得出了最初的结论,并且只有在实际尝试后才发现我的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.