我有两个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状态)时,我看到:
$ sudo bluepill status
powerupserver(pid:0): up
outputserver(pid:0): up所以它应该是up的(尽管pid为0?这当然看起来不太好),但我可以看到他们没有运行/做他们应该做的事情。有Bluepill知识的人能帮我找出我哪里做错了吗?非常感谢你提前这么多!
发布于 2012-09-25 07:47:31
我最终使用Daemons ruby gem来守护我的脚本,并使用Bluepill来监控它们。我知道只使用Bluepill就可以做到这两点,但我当时想不出来,我的系统一直工作得很好。我使用的是Rails 3.0.3、Daemons 1.1.5和Bluepill 0.0.51。所以首先要做的是,确保你安装了守护进程和Bluepill。
假设我们有myserver.rb,一个驻留在我的rails应用程序根目录中的ruby服务器脚本。为了使用守护进程对其进行守护进程,请在根文件夹中创建myserver_control.rb,以告诉守护进程如何进行守护进程:
# myserver_control.rb
require 'rubygems'
require 'daemons'
@options = {
:dir_mode => :normal,
:dir => '/Library/WebServer/myrailsapp/pids',
:multiple => true,
:backtrace => true,
:monitor => false,
:log_dir => '/Library/WebServer/myrailsapp/log',
:log_output => true
}
Daemons.run('myserver.rb', @options)查看守护程序文档以了解有关选项散列的更多信息。你现在可以在你的rails应用根文件夹内的命令行中使用'sudo ruby myserver_control.rb start‘来运行你的守护进程。这是守护程序启动命令,您可以将其放入Bluepill配置文件(myrailsapp.pill文件)中,如下所示:
Bluepill.application("myrailsapp", :foreground => false, :log_file => "/Library/WebServer/myrailsapp/log/bluepill.log") do |app|
app.process("myserver") do |process|
process.start_command = "sudo ruby myserver_control.rb start"
process.stop_command = "sudo ruby myserver_control.rb stop"
process.restart_command = "sudo ruby myserver_control.rb restart"
process.pid_file = "/Library/WebServer/myrailsapp/pids/myserver.rb0.pid"
process.working_dir = "/Library/WebServer/myrailsapp"
process.start_grace_time = 5.seconds
process.stop_grace_time = 5.seconds
process.restart_grace_time = 8.seconds
end
end请务必阅读Bluepill文档以了解您的所有选择。然后,当您启动Bluepill时,您将拥有一个受监视的守护进程。确保上述示例中引用的所有文件夹都存在(例如pids)。
https://stackoverflow.com/questions/8417423
复制相似问题