0

I'm trying to deploy a simple Rails app with a couple of Resque workers. Since I need the workers to run in the background I'm using God to manage them. When running the workers from the command line it runs just fine:

QUEUE=* /var/www/billtune/shared/bundle/ruby/1.9.1/bin/rake -f /var/www/billtune/current/Rakefile environment rescue:work

But when they are run by God it seems that the processes keep crashing. Looking at the log files it seems to be related to 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)

How come a JavaScript runtime is missing when running by God, but not missing when running directly??

For the sake of completeness I'm also attaching the relevant God file:

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
Avinash Singh
  • 4,970
  • 8
  • 20
  • 35
shaimo
  • 376
  • 3
  • 17
  • it starts up the rails application and i guess you are using some asset stuff in there that requires a javascript compiler. – phoet Nov 19 '13 at 10:22
  • @shaimo are you sure that god is running in write environment I mean try giving user and guid god since god most start with sudo it would run the code in sudo mode hence the binary wont be available in sudo user – Viren Nov 27 '13 at 12:06
  • @Viren - thanks for your reply. Indeed God is currently root user and group. What do you suggest I change it to? Doesn't it need the root permissions in order to start and stop processes? – shaimo Dec 02 '13 at 22:32
  • @phoet - Thanks. So how come it doesn't require it when running it from the command line? – shaimo Dec 02 '13 at 22:34
  • @shaimo define the `uid` and `guid` in `god config` and god would run your rake with that user and you would not have issue of missing gem then – Viren Dec 04 '13 at 13:45

0 Answers0