使用 bluepill 监控捆绑执行 unicorn_rails

发布于 11-14 03:50 字数 1404 浏览 8 评论 0原文

由于 unicorn_rails 抱怨不同的 gem 版本,我们转而在 bluepill 文件中运行 bundle exec unicorn_rails... 。此更改解决了该特定问题,并且事情开始和停止,但是当我们尝试 sudo bluepill status 时,我们现在得到

unicorn(pix: XXXXXX): unmonitored

看起来 bluepill 现在没有监视 unicorn 进程。如果我停止子进程,它将重新启动子进程,但不会重新启动父进程。

我四处搜寻,但找不到太多关于这个问题的信息,希望有人能对此有所了解。 bluepill 配置文件是

app_dir = "/opt/local/share/httpd/apps/xyz"
Bluepill.application('xyz', :log_file => "#{app_dir}/current/log/bluepill.log") do |app|
  app.process('unicorn') do |process|
    process.pid_file    = "#{app_dir}/shared/pids/unicorn.pid"
    process.working_dir = "#{app_dir}/current"

    process.stdout = process.stderr = "#{app_dir}/shared/log/unicorn.err.log"
    process.start_command = "bundle exec unicorn_rails -D -c #{app_dir}/current/config/environments/production/unicorn.rb -E production"
    process.stop_command = "kill -QUIT {{PID}}"
    process.restart_command = "kill -USR2 {{PID}}"

    process.start_grace_time = 8.seconds
    process.stop_grace_time = 5.seconds
    process.restart_grace_time = 13.seconds

    process.monitor_children do |child_process|
      child_process.stop_command = "kill -QUIT {{PID}}"

      child_process.checks :mem_usage, :every => 10.seconds, :below => 200.megabytes, :times => [3,5]
      child_process.checks :cpu_usage, :every => 10.seconds, :below => 50, :times => [3,5]
    end
  end

end

Due to unicorn_rails complaining about different gem versions we moved to running bundle exec unicorn_rails... in our bluepill files. This change solved that particular problem and things start and stop but when we try sudo bluepill status we now get

unicorn(pix: XXXXXX): unmonitored

Which looks like bluepill is not monitoring the unicorn processes now. It will restart the child processes if I stop them but won't restart the parent process.

I've searched around but can't find much about this issue and was hoping someone could shed some light on it. The bluepill config file is

app_dir = "/opt/local/share/httpd/apps/xyz"
Bluepill.application('xyz', :log_file => "#{app_dir}/current/log/bluepill.log") do |app|
  app.process('unicorn') do |process|
    process.pid_file    = "#{app_dir}/shared/pids/unicorn.pid"
    process.working_dir = "#{app_dir}/current"

    process.stdout = process.stderr = "#{app_dir}/shared/log/unicorn.err.log"
    process.start_command = "bundle exec unicorn_rails -D -c #{app_dir}/current/config/environments/production/unicorn.rb -E production"
    process.stop_command = "kill -QUIT {{PID}}"
    process.restart_command = "kill -USR2 {{PID}}"

    process.start_grace_time = 8.seconds
    process.stop_grace_time = 5.seconds
    process.restart_grace_time = 13.seconds

    process.monitor_children do |child_process|
      child_process.stop_command = "kill -QUIT {{PID}}"

      child_process.checks :mem_usage, :every => 10.seconds, :below => 200.megabytes, :times => [3,5]
      child_process.checks :cpu_usage, :every => 10.seconds, :below => 50, :times => [3,5]
    end
  end

end

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

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

发布评论

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

评论(2

魂归处2024-11-21 03:50:09

当您运行 bundle exec 时,它会设置一个环境并分叉 unicorn_rails 进程。 Bluepill 最终监视原始的 bundle exec 进程而不是 unicorn,这就是您看到不受监视的原因。

我直接在 bluepill 中设置捆绑器环境,然后直接执行 unicorn_rails :(

Bluepill.application('xyz') do |app|
  app.environment = `env -i BUNDLE_GEMFILE=#{app_dir}/Gemfile bundle exec env`.lines.inject({}) do |env_hash,l|
    kv = l.chomp.split('=',2)
    env_hash[kv[0] = kv[1]
    env_hash
  end

  app.process('unicorn') do |process|
    process.start_command = "unicorn_rails -D -c #{app_dir}/current/config/environments/production/unicorn.rb -E production"
  end
end

注意:为了清楚起见,我省略了上述配置文件的一部分。您的配置文件看起来不错,只需尝试添加 app .environment 上面的东西,并从启动命令中删除 bundle exec 。)

这通过使用反引号捕获捆绑器环境变量,将返回的字符串解析为散列并分配来设置 bluepill 中的环境它到app.environment

When you run bundle exec, it sets up an environment and forks the unicorn_rails process. Bluepill ends up monitoring the original bundle exec process instead of unicorn which is why you see unmonitored.

I set up my bundler environment directly in bluepill and then execute unicorn_rails directly:

Bluepill.application('xyz') do |app|
  app.environment = `env -i BUNDLE_GEMFILE=#{app_dir}/Gemfile bundle exec env`.lines.inject({}) do |env_hash,l|
    kv = l.chomp.split('=',2)
    env_hash[kv[0] = kv[1]
    env_hash
  end

  app.process('unicorn') do |process|
    process.start_command = "unicorn_rails -D -c #{app_dir}/current/config/environments/production/unicorn.rb -E production"
  end
end

(Note: I omitted part of the above config file for clarity. Your config file looks good, just try adding the app.environment stuff above and removing bundle exec from your start command.)

This sets up the environment in bluepill by capturing the bundler environment variables using backticks, parsing the returned string into a hash and assigning it to app.environment.

心奴独伤2024-11-21 03:50:09

我知道这个问题很老了,但我已经面临这个问题好几个星期了。当我意识到“bluepill 退出”后,我开始怀疑,然后在 unicorn 运行时重新加载药丸,让 bluepill 认为进程“启动”。

@blt04 的回答没有帮助。今天我恍然大悟。我的 8 秒宽限启动时间还不够,因为我的独角兽配置中有 preload_app true...并且我的应用程序 (Rails) 需要 12 秒加载,而不是 8 秒。

将启动时间提高到30 秒(大大超出了所需时间)解决了问题。 Bluepill 只是说“开始”30 秒,然后正确地转到“向上”。 Unicorn 正常启动并运行。

您还希望重新启动时间比 Rails 启动所需的时间长。

I know this question is old, but I've been facing this problem for weeks. My suspicions were aroused when I realised that 'bluepill quit', followed by reloading the pill while unicorn was running allowed bluepill to consider the process 'up'.

@blt04's answer didn't help. Today I came to a realization. My grace start time of 8 seconds was not enough, because I had preload_app true in my unicorn config... and my app (Rails) takes 12 seconds to load, not 8.

Raising the start time to 30 seconds (wildly in excess of what was needed) solved the problem. Bluepill just says 'starting' for 30 seconds, then goes to 'up' correctly. Unicorn starts and runs as normal.

You'll want your restart time to be longer than it takes for Rails to start too.

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