Created
January 12, 2011 08:51
-
-
Save iain/775894 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
God.watch do |w| | |
DEFAULT.call(w) | |
w.name = "delayed_job" | |
w.start = "bundle exec #{RAILS_ROOT}/script/delayed_job -e #{RAILS_ENV} run" | |
w.pid_file = "#{RAILS_ROOT}/tmp/pids/delayed_job.pid" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless RAILS_ENV == 'development' | |
God.watch do |w| | |
DEFAULT.call(w) | |
w.name = "memcached" | |
w.pid_file = "#{RAILS_ROOT}/tmp/pids/memcached.pid" | |
w.start = "memcached -d -P #{w.pid_file}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# although you need mysql in development too, this watch | |
# is for production only, because it requires God to be root. | |
# | |
# Also, don't forget to configure my.cnf to store a pid-file. | |
unless RAILS_ENV == 'development' | |
God.watch do |w| | |
LIFECYCLE.call(w) | |
w.name = 'mysqld' | |
mysql = lambda { |cmd| "/etc/init.d/mysqld #{cmd}" } | |
w.start = mysql[:start] | |
w.stop = mysql[:stop] | |
w.restart = mysql[:restart] | |
w.pid_file = "/var/run/mysqld/mysqld.pid" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unless RAILS_ENV == 'development' | |
God.watch do |w| | |
w.name = 'nginx' | |
w.group = 'group-name' | |
w.pid_file = "/var/run/nginx.pid" | |
nginx = lambda { |cmd| "/etc/init.d/nginx #{cmd}" } | |
w.start = nginx[:start] | |
w.stop = nginx[:stop] | |
w.restart = nginx[:restart] | |
w.interval = 30.seconds | |
w.start_grace = 10.seconds | |
w.restart_grace = 10.seconds | |
w.restart_if do |restart| | |
restart.condition(:memory_usage) do |c| | |
c.above = 1024.megabytes | |
c.times = [3,5] | |
end | |
restart.condition(:cpu_usage) do |c| | |
c.above = 50.percent | |
c.times = 5 | |
end | |
end | |
w.start_if do |on| | |
on.condition(:http_response_code) do |c| | |
c.host = 'localhost' | |
c.port = 80 | |
c.path = '/' | |
c.code_is_not = (200..399).to_a | |
c.timeout = 10.seconds | |
c.times = [2, 5] | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
God.watch do |w| | |
DEFAULT.call(w) | |
sunspot = lambda { |cmd| "bundle exec rake sunspot:solr:#{cmd}" } | |
w.name = "solr" | |
w.start = sunspot.call("start") | |
w.stop = sunspot.call("stop") | |
w.restart = "#{w.stop} && #{w.start}" | |
w.pid_file = "#{RAILS_ROOT}/tmp/pids/sunspot-solr-#{RAILS_ENV}.pid" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RAILS_ENV = ENV['RAILS_ENV'] || 'production' | |
RAILS_ROOT = ENV['RAILS_ROOT'] || File.expand_path('../../..', __FILE__) | |
God.terminate_timeout = 20.seconds | |
God.pid_file_directory = "#{RAILS_ROOT}/tmp/pids/" | |
LIFECYCLE = lambda do |w| | |
w.group = 'group-name' | |
w.dir = RAILS_ROOT | |
w.env = { 'RAILS_ENV' => RAILS_ENV } | |
w.grace = 15.seconds | |
w.interval = 30.seconds | |
w.behavior :clean_pid_file | |
w.start_if do |start| | |
start.condition(:process_running) do |c| | |
c.interval = 5.seconds | |
c.running = false | |
end | |
end | |
w.restart_if do |restart| | |
restart.condition(:memory_usage) do |c| | |
c.above = 1024.megabytes | |
c.times = [3,5] # 3 out of 5 intervals | |
end | |
restart.condition(:cpu_usage) do |c| | |
c.above = 50.percent | |
c.times = 5 | |
end | |
end | |
w.lifecycle do |on| | |
on.condition(:flapping) do |c| | |
c.to_state = [:start, :restart] | |
c.times = 5 | |
c.within = 5.minute | |
c.transition = :unmonitor | |
c.retry_in = 10.minutes | |
c.retry_times = 5 | |
c.retry_within = 2.hours | |
end | |
end | |
end | |
if RAILS_ENV == "production" | |
DEFAULT = lambda do |w| | |
LIFECYCLE.call(w) | |
w.uid = 'deploy' | |
w.gid = 'deploy' | |
end | |
else | |
DEFAULT = LIFECYCLE | |
end | |
God.load "#{RAILS_ROOT}/config/god/_*.god" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment