Read more

Resque + God + Capistrano

Tobias Kraze
August 02, 2011Software engineer at makandra GmbH

Attached is a working config to deploy an application with Capistrano Show archive.org snapshot that needs to monitor Resque Show archive.org snapshot workers with God Show archive.org snapshot .

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

God will run as the deployment user, no need to register it as a system service.

Put this into your config/deploy.rb:

namespace :god do
  def god_is_running
    !capture("#{god_command} status >/dev/null 2>/dev/null || echo 'not running'").start_with?('not running')
  end

  def god_command
    "cd #{current_path}; bundle exec god"
  end

  desc "Stop god"
  task :terminate_if_running do
    if god_is_running
      run "#{god_command} terminate"
    end
  end

  desc "Start god"
  task :start do
    config_file = "#{current_path}/config/resque.god"
    environment = { :RAILS_ENV => rails_env, :RAILS_ROOT => current_path }
    run "#{god_command} -c #{config_file}", :env => environment
  end
end

before "deploy:update", "god:terminate_if_running"
after "deploy:update", "god:start"

Put the attached resque.god config into your applications config directory.

You can adjust the number of workers there.

Posted by Tobias Kraze to makandra dev (2011-08-02 13:24)