upstart + bluepill + unicorn&使用rvm和bundler的delayed_job:`exec':没有这样的文件或目录

时间:2012-01-05 02:43:21

标签: rvm delayed-job bluepill

我正在努力让我的独角兽和delayed_job进程重新启动。我已经决定使用bluepill作为整体经理,因为这可以很容易地在Ubuntu中与upstart一起开始。我为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,捆绑器管理了宝石。我应该提到这是一个Rails 3.1应用程序。

基本上当我在没有delayed_job运行的情况下启动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,它只是说它找不到捆绑可执行文件。我怀疑是环境没有正确加载。有小费吗?我有一个RVM gemset,它是从项目根目录中的.rvmrc文件加载的。我是否应该在bluepill配置中切换到这个gemset?

1 个答案:

答案 0 :(得分:0)

好的,所以最后很容易。我认为发生的事情是我在全局rvm gemset中以root身份安装了bluepill,并创建了我的包装器以在环境中使用全局gemset(意味着bluepill开始正常,但它没有看到我正确的gemset中的任何其他宝石(保证))。我基本上从全局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中加载完整的gems集。