0

我在让我的独角兽和delayed_job 进程防重启方面有些挣扎。我已经决定使用 bluepill 作为整体经理,因为这可以很容易地从 Ubuntu 中的暴发户开始。我为 bluepill 创建了一个 RVM 包装器,并且 upstart 脚本运行良好(轻松启动和停止:

# bluepill - process monitor
#
# simple process monitoring tool

description "simple process monitoring tool"

start on started nginx
stop on stopping nginx

expect daemon
#respawn

exec bootup_bluepill load /home/deployer/apps/nzswarranty/current/config/production.pill

接下来是 bluepill 配置文件:

Bluepill.application("nzswarranty", :log_file => "/var/log/bluepill.log") do |app|
  app.working_dir = '/home/deployer/apps/nzswarranty/current'
  app.uid = "deployer"
  app.gid = "staff"

  app.process("unicorn") do |process|
    process.start_command = "bundle exec unicorn_rails -c config/unicorn.rb -D"
    process.stop_command  = "kill -s QUIT `cat /tmp/unicorn.nzswarranty.pid`"
    process.restart_command  = "kill -s USR2 `cat /tmp/unicorn.nzswarranty.pid`"
    process.pid_file = '/tmp/unicorn.nzswarranty.pid'
    process.start_grace_time = 15.seconds
    process.stop_grace_time = 15.seconds
  end

  app.process("delayed_job") do |process|
    process.environment = { 'RAILS_ENV' => 'production' }
    process.start_command = 'script/delayed_job start'
    process.stop_command  = 'script/delayed_job stop'
    process.pid_file = '/home/deployer/apps/nzswarranty/shared/pids/delayed_job.pid'
    process.start_grace_time = 15.seconds
    process.stop_grace_time = 15.seconds
  end

end

该服务器安装了系统范围的 RVM 并使用捆绑程序管理 gem。我应该提到这是一个 Rails 3.1 应用程序。

基本上,当我在没有延迟作业的情况下启动 bluepill 时,当它尝试启动它时我会得到这个:

W, [2012-01-05T13:37:55.185626 #28201]  WARN -- : [nzswarranty:delayed_job] Start command execution returned non-zero exit code:
W, [2012-01-05T13:37:55.185780 #28201]  WARN -- : [nzswarranty:delayed_job] {:stdout=>"", :stderr=>"/usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no such file to load -- bundler/setup (LoadError)\n\tfrom /usr/local/rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'\n\tfrom /home/deployer/apps/nzswarranty/current/config/boot.rb:6:in `<top (required)>'\n\tfrom <internal:lib/rubygems/custom_require>:29:in `require'\n\tfrom <internal:lib/rubygems/custom_require>:29:in `require'\n\tfrom /home/deployer/apps/nzswarranty/current/config/application.rb:1:in `<top (required)>'\n\tfrom <internal:lib/rubygems/custom_require>:29:in `require'\n\tfrom <internal:lib/rubygems/custom_require>:29:in `require'\n\tfrom /home/deployer/apps/nzswarranty/current/config/environment.rb:2:in `<top (required)>'\n\tfrom <internal:lib/rubygems/custom_require>:29:in `require'\n\tfrom <internal:lib/rubygems/custom_require>:29:in `require'\n\tfrom script/delayed_job:3:in `<main>'\n", :exit_code=>1}
I, [2012-01-05T13:37:55.186003 #28201]  INFO -- : [nzswarranty:delayed_job] Going from down => starting

我也尝试过为此使用 bundle exec ,它只是说它找不到 bundle 可执行文件。我怀疑环境没有正确加载。有小费吗?我有一个从项目根目录中的 .rvmrc 文件加载的 RVM gemset。我也应该在 bluepill 配置中切换到这个 gemset 吗?

4

1 回答 1

0

好的,所以最后很容易。我认为发生的事情是我以 root 身份在全局 rvm gemset 中安装了 bluepill,并且还创建了我的包装器以在环境中使用全局 gemset(这意味着 bluepill 启动正常,但在我的正确 gemset 中没有看到任何其他 gem (保修单))。我基本上从全局 gemset 中删除了 bluepill 并将其安装在保修 gemset 中。然后我再次创建了包装器:

rvmsudo rvm wrapper ruby-1.9.2-p290@warranty bootup bluepill

我在尝试启动独角兽时还遇到了另一个奇怪的错误,但我意识到我没有传入 RAILS_ENV。这是我的最终 .pill:

Bluepill.application("nzswarranty", :log_file => "/var/log/bluepill.log") do |app|
    app.working_dir = '/home/deployer/apps/nzswarranty/current'
    app.uid = 'deployer'
    app.gid = 'staff'
    app.environment = { 'RAILS_ENV' => 'production' }

    app.process("unicorn") do |process|
        process.start_command = "bundle exec unicorn_rails -c config/unicorn.rb -D"
        process.stop_command  = "kill -s QUIT `cat /tmp/unicorn.nzswarranty.pid`"
        process.restart_command  = "kill -s USR2 `cat /tmp/unicorn.nzswarranty.pid`"
        process.pid_file = '/tmp/unicorn.nzswarranty.pid'
        process.start_grace_time = 30.seconds
        process.stop_grace_time = 30.seconds
    end

    app.process("delayed_job") do |process|
        process.start_command = 'bundle exec script/delayed_job start'
        process.stop_command  = 'bundle exec script/delayed_job stop'
        process.pid_file = '/home/deployer/apps/nzswarranty/shared/pids/delayed_job.pid'
        process.start_grace_time = 30.seconds
        process.stop_grace_time = 30.seconds
    end
end

重要的是要注意,我们需要在其他命令之前使用 bundle exec,以便我们从 Gemfile 加载全套 gem。

于 2012-01-13T03:18:09.013 回答