いくつかの Resque ワーカーを使用して単純な Rails アプリをデプロイしようとしています。ワーカーをバックグラウンドで実行する必要があるため、神を使用してそれらを管理しています。コマンドラインからワーカーを実行すると、問題なく実行されます。
QUEUE=* /var/www/billtune/shared/bundle/ruby/1.9.1/bin/rake -f /var/www/billtune/current/Rakefile environment rescue:work
しかし、それらが神によって実行されている場合、プロセスはクラッシュし続けるようです。ログ ファイルを見ると、execjs に関連しているようです。
rake aborted!
Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/execjs-2.0.2/lib/execjs/runtimes.rb:51:in `autodetect'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/execjs-2.0.2/lib/execjs.rb:5:in `<module:ExecJS>'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/execjs-2.0.2/lib/execjs.rb:4:in `<top (required)>'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/coffee-script-2.2.0/lib/coffee_script.rb:1:in `<top (required)>'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/coffee-script-2.2.0/lib/coffee-script.rb:1:in `<top (required)>'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `block in require'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:251:in `require'
/var/www/billtune/shared/bundle/ruby/1.9.1/gems/coffee-rails-3.2.2/lib/coffee-rails.rb:1:in `<top (required)>'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p448/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
/var/www/billtune/current/config/application.rb:7:in `<top (required)>'
/var/www/billtune/current/Rakefile:5:in `require'
/var/www/billtune/current/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)
神によって実行されたときにJavaScriptランタイムが欠落しているのに、直接実行すると欠落していないのはなぜですか??
完全を期すために、関連する神のファイルも添付しています。
rails_env = ENV['RAILS_ENV'] || "production"
rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/..'
num_workers = rails_env == 'production' ? 2 : 1
puts "rails_root=" + rails_root
num_workers.times do |num|
God.watch do |w|
w.dir = "#{rails_root}"
w.name = "resque-#{num}"
w.group = 'resque'
w.interval = 30.seconds
w.env = {"QUEUE"=>"*", "RAILS_ENV"=>rails_env}
w.start = "bundle exec rake -f #{rails_root}/Rakefile environment resque:work"
w.log = "#{rails_root}/log/resque-#{num}.log"
w.err_log = "#{rails_root}/log/resque_error-#{num}.log"
# w.uid = 'git'
# w.gid = 'git'
# restart if memory gets too high
w.transition(:up, :restart) do |on|
on.condition(:memory_usage) do |c|
c.above = 350.megabytes
c.times = 2
end
end
# determine the state on startup
w.transition(:init, { true => :up, false => :start }) do |on|
on.condition(:process_running) do |c|
c.running = true
end
end
# determine when process has finished starting
w.transition([:start, :restart], :up) do |on|
on.condition(:process_running) do |c|
c.running = true
c.interval = 5.seconds
end
# failsafe
on.condition(:tries) do |c|
c.times = 5
c.transition = :start
c.interval = 5.seconds
end
end
# start if process is not running
w.transition(:up, :start) do |on|
on.condition(:process_running) do |c|
c.running = false
end
end
end
end