如何使用 Bluepill 启动并运行 ruby​​ 服务器脚本?

发布于 2024-12-19 22:10:47 字数 1822 浏览 1 评论 0原文

我有两个 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 技术交流群。

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

发布评论

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

评论(1

九命猫 2024-12-26 22:10:47

我最终使用 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 以告诉守护程序如何进行守护程序:

# 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)

查看守护程序文档以了解有关选项哈希的更多信息。现在,您可以使用“sudo ruby​​ myserver_control.rb start”在命令行中从 Rails 应用程序根文件夹内运行守护程序。这是守护程序启动命令,您可以将其放入 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)。

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:

# 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)

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:

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

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).

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