如何使用 Bluepill 启动并运行 ruby 服务器脚本?
我有两个 ruby 服务器脚本,powerupserver.rb 和 outputserver.rb,其形式为:
require '/Library/WebServer/sample_app/config/environment'
# more requires
@server = TCPServer.open(port_number)
loop do
Thread.start(@server.accept) do |sock|
# do stuff
end
end
在开发中,我使用 Foreman 来运行它们,效果很好。现在我尝试使用 Bluepill 作为守护进程在后台运行和监控它们。我选择 Bluepill 主要是因为 Foreman 可以选择导出到 Bluepill 配置文件(.pill 文件)。因此,我这样做了,然后根据需要更改了 .pill 文件以获得以下内容:
Bluepill.application("sample_app", :foreground => false, :log_file => "/var/bluepill/log/bluepill.log") do |app|
app.process("powerupserver") do |process|
process.start_command = "ruby powerupserver.rb"
process.working_dir = "/Library/WebServer/sample_app"
process.pid_file = "/var/bluepill/pids/powerupserver-1.pid"
process.daemonize = true
process.stdout = process.stderr = "/var/bluepill/log/powerupserver-1.log"
process.start_grace_time = 3.seconds
process.stop_grace_time = 5.seconds
process.restart_grace_time = 8.seconds
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
process.checks :cpu_usage, :every => 10.seconds, :below => 5, :times => 3
process.checks :mem_usage, :every => 10.seconds, :below => 100.megabytes, :times => [3,5]
process.checks :flapping, :times => 2, :within => 30.seconds, :retry_in => 7.seconds
end
# more lines here mimicking above, but for server script 'outputserver.rb'
end
当我加载此 .pill 并检查状态(sudo bluepill status)时,我看到:
$ sudo bluepill status
powerupserver(pid:0): up
outputserver(pid:0): up
所以它应该已启动(尽管 pid 为 0?这看起来当然不太好),但我可以看到他们没有运行/做他们应该做的事情。有 Bluepill 知识的人可以帮我弄清楚我在这里做错了什么吗?非常感谢您提前!
I have two ruby server scripts, powerupserver.rb and outputserver.rb, of the form:
require '/Library/WebServer/sample_app/config/environment'
# more requires
@server = TCPServer.open(port_number)
loop do
Thread.start(@server.accept) do |sock|
# do stuff
end
end
In development I use Foreman to run them and that works great. Now I am trying to run and monitor them in the background as daemons with Bluepill. I chose Bluepill mostly because Foreman has an option to export to a Bluepill config file (.pill file). So I did that and then altered the .pill file as needed to get the following:
Bluepill.application("sample_app", :foreground => false, :log_file => "/var/bluepill/log/bluepill.log") do |app|
app.process("powerupserver") do |process|
process.start_command = "ruby powerupserver.rb"
process.working_dir = "/Library/WebServer/sample_app"
process.pid_file = "/var/bluepill/pids/powerupserver-1.pid"
process.daemonize = true
process.stdout = process.stderr = "/var/bluepill/log/powerupserver-1.log"
process.start_grace_time = 3.seconds
process.stop_grace_time = 5.seconds
process.restart_grace_time = 8.seconds
process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
process.checks :cpu_usage, :every => 10.seconds, :below => 5, :times => 3
process.checks :mem_usage, :every => 10.seconds, :below => 100.megabytes, :times => [3,5]
process.checks :flapping, :times => 2, :within => 30.seconds, :retry_in => 7.seconds
end
# more lines here mimicking above, but for server script 'outputserver.rb'
end
When I load this .pill, and check the status (sudo bluepill status), I see:
$ sudo bluepill status
powerupserver(pid:0): up
outputserver(pid:0): up
So it is supposedly up (albeit with pid's of 0? which certainly doesn't seem good), but I can see that they are not running/doing what they're supposed to do. Could someone with Bluepill knowledge help me figure out what I'm doing wrong here? Thank you so so much in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终使用 Daemons ruby gem 来守护我的脚本并使用 Bluepill 来监视它们。我知道您可以仅使用 Bluepill 来完成这两项操作,但当时我无法弄清楚,而且我的系统一直运行良好。我正在使用 Rails 3.0.3、Daemons 1.1.5 和 Bluepill 0.0.51。首先,请确保您已安装 Daemons 和 Bluepill。
假设我们有 myserver.rb,这是一个位于我的 Rails 应用程序根目录中的 ruby 服务器脚本。为了使用守护程序对其进行守护程序,请在根文件夹中创建 myserver_control.rb 以告诉守护程序如何进行守护程序:
查看守护程序文档以了解有关选项哈希的更多信息。现在,您可以使用“sudo ruby myserver_control.rb start”在命令行中从 Rails 应用程序根文件夹内运行守护程序。这是守护程序启动命令,您可以将其放入 Bluepill 配置文件(myrailsapp.pill 文件)中,如下所示:
一定要阅读 Bluepill 文档以查看所有选项。然后,当您启动 Bluepill 时,您就有了一个受监控的守护进程。确保上面示例中引用的所有文件夹都存在(例如 pids)。
I ended up using the Daemons ruby gem to daemonize my scripts and using Bluepill to monitor them. I know you can do both using only Bluepill, but I couldn't figure it out at the time and my system has been working just fine. I am using Rails 3.0.3, Daemons 1.1.5 and Bluepill 0.0.51. So first things first, make sure you have Daemons and Bluepill installed.
So let's say we have myserver.rb, a ruby server script living inside my rails app root. In order to daemonize it with Daemons, create myserver_control.rb within the root folder to tell Daemons how to daemonize:
Check out the Daemon documentation to learn more about the options hash. You can now run your daemon from inside your rails app root folder at the command line using 'sudo ruby myserver_control.rb start'. This is the daemon start up command that you can put in your Bluepill config file (myrailsapp.pill file) like so:
Definitely go read up on the Bluepill documentation to see all of your many options. Then when you start up Bluepill you have a monitored daemon. Make sure all of the folders referenced in the examples above exist (e.g. pids).