使用bluepill监视bundle exec unicorn_rails

use*_*078 5 unicorn bundler bluepill

由于unicorn_rails抱怨不同的gem版本,我们在bluepill文件中移动了bundle exec unicorn_rails ... 这个变化解决了特定问题和事情的开始和停止,但是当我们尝试sudo bluepill状态时,我们现在得到了

独角兽(pix:XXXXXX):不受监控

看起来像bluepill现在没有监控独角兽进程.如果我停止子进程,它将重新启动子进程,但不会重新启动父进程.

我已经四处寻找,但对这个问题找不到多少,并希望有人可以对此有所了解.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
Run Code Online (Sandbox Code Playgroud)

blt*_*t04 3

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

我直接在bluepill中设置我的bundler环境,然后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
Run Code Online (Sandbox Code Playgroud)

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

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