Skip to content

Instantly share code, notes, and snippets.

@tispratik
Created June 10, 2011 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tispratik/1019849 to your computer and use it in GitHub Desktop.
Save tispratik/1019849 to your computer and use it in GitHub Desktop.
God Config File
God.log_level = :debug
ENV['RAILS_ENV'] ||= "staging"
ENV['RAILS_ROOT'] ||= ENV['RAILS_ENV'] == "development" ? "." : "/home/rails/public_html/myapp/current"
ENV['GOD_UID'] ||= ENV['RAILS_ENV'] == "development" ? ENV["LOGNAME"] : "rails"
ENV['GOD_GID'] ||= ENV['RAILS_ENV'] == "development" ? "staff" : "rails"
puts "God is starting with:"
puts "RAILS_ENV = #{ENV['RAILS_ENV']}"
puts "RAILS_ROOT = #{ENV['RAILS_ROOT']}"
puts "GOD_UID = #{ENV['GOD_UID']}"
puts "GOD_GID = #{ENV['GOD_GID']}"
God.pid_file_directory = "#{ENV['RAILS_ROOT']}/tmp/pids"
God.watch do |w|
w.name = "myapp_delayed_job"
w.interval = 30.seconds
#w.pid_file = "#{ENV['RAILS_ROOT']}/tmp/pids/myapp_delayed_job.pid"
#w.dir = ENV['RAILS_ROOT']
w.env = { 'RAILS_ENV' => ENV['RAILS_ENV'] }
w.start = "rake jobs:work"
w.stop = "kill -9 `cat #{w.pid_file}`"
w.log = "#{ENV['RAILS_ROOT']}/log/delayed_job.god.log"
w.behavior(:clean_pid_file)
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment