Skip to content

Instantly share code, notes, and snippets.

@anathematic
Created December 16, 2009 08:53
Show Gist options
  • Save anathematic/257696 to your computer and use it in GitHub Desktop.
Save anathematic/257696 to your computer and use it in GitHub Desktop.
Thinking Sphinx God script
APP_PATH = "/home/wotvenue/rails_app/staging.foo.com"
RAILS_ROOT = "/home/wotvenue/rails_app/staging.foo.com/current/"
RAILS_ENV = "production"
God.watch do |w|
w.name = "thinking-sphinx-staging"
w.interval = 25.seconds # default
w.start = "cd #{RAILS_ROOT} && ruby script/ts:start RAILS_ENV=#{RAILS_ENV}"
w.stop = "cd #{RAILS_ROOT} && ruby script/ts:stop RAILS_ENV=#{RAILS_ENV}"
w.restart = "cd #{RAILS_ROOT} && ruby script/ts:index RAILS_ENV=#{RAILS_ENV}"
w.pid_file = File.join("#{APP_PATH}/shared/searchd.#{RAILS_ENV}.pid")
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
end
# failsafe
on.condition(:tries) do |c|
c.times = 5
c.transition = :start
end
end
# start if process is not running
w.transition(:up, :start) do |on|
on.condition(:process_exits)
end
# lifecycle
w.lifecycle do |on|
on.condition(:flapping) do |c|
c.to_state = [:start, :restart]
c.times = 5
c.within = 5.minute
c.transition = :unmonitored
c.retry_in = 10.minutes
c.retry_times = 5
c.retry_within = 2.hours
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment