Skip to content

Instantly share code, notes, and snippets.

@jnewland
Created September 16, 2009 13:58
Show Gist options
  • Save jnewland/188053 to your computer and use it in GitHub Desktop.
Save jnewland/188053 to your computer and use it in GitHub Desktop.
after "deploy:setup", "thinking_sphinx:shared_sphinx_folder"
after 'deploy:finalize_update', 'thinking_sphinx:symlink_indexes'
after 'deploy:restart', 'thinking_sphinx:restart'
namespace :thinking_sphinx do
task :symlink_indexes, :roles => [:app] do
run "ln -nfs #{shared_path}/db/sphinx #{latest_release}/db/sphinx"
end
task :restart do
configure
god.app.delayed_delta.stop
god.app.searchd.restart
god.app.delayed_delta.start
end
end
require 'san_juan'
set :god_config_path, "/etc/god/god.conf"
san_juan.role :app, %w(delayed_delta searchd)
God.watch do |w|
w.name = "delayed_delta"
w.group = "sphinx"
w.interval = 30.seconds
w.start = "rake -f #{RAILS_ROOT}/Rakefile thinking_sphinx:delayed_delta"
w.env = { "RAILS_ENV" => "production"}
w.uid = 'rails'
w.gid = 'rails'
# retart if memory gets too high
w.transition(:up, :restart) do |on|
on.condition(:memory_usage) do |c|
c.above = 300.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
God.watch do |w|
w.name = "searchd"
w.group = "sphinx"
w.interval = 30.seconds
w.start = "searchd --config #{RAILS_ROOT}/config/#{RAILS_ENV}.sphinx.conf"
w.start_grace = 10.seconds
w.stop = "searchd --config #{RAILS_ROOT}/config/#{RAILS_ENV}.sphinx.conf --stop"
w.stop_grace = 10.seconds
w.pid_file = "#{RAILS_ROOT}/log/searchd.#{RAILS_ENV}.pid"
w.uid = 'rails'
w.gid = 'rails'
# retart if memory gets too high
w.transition(:up, :restart) do |on|
on.condition(:memory_usage) do |c|
c.above = 300.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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment