Created
May 10, 2011 07:45
-
-
Save denmarkin/964060 to your computer and use it in GitHub Desktop.
God recipes examples for Rackspace Cloud (Ubuntu) with resque and php-cgi. Try any of them with "sudo god -c /path/to/config -D"
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| | |
w.name = "mysqld" | |
w.interval = 30.seconds # default | |
w.start = "service mysql start" | |
w.stop = "service mysql stop" | |
w.restart = "service mysql restart" | |
w.start_grace = 20.seconds | |
w.restart_grace = 20.seconds | |
w.pid_file = "/var/lib/mysql/hostname.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 = 8 | |
c.within = 2.minutes | |
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 = 1.minute | |
c.transition = :unmonitored | |
c.retry_in = 10.minutes | |
c.retry_times = 5 | |
c.retry_within = 2.hours | |
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| | |
w.name = "nginx" | |
w.interval = 30.seconds # default | |
w.start = "service nginx start" | |
w.stop = "service nginx stop" | |
w.restart = "service nginx restart" | |
w.start_grace = 20.seconds | |
w.restart_grace = 20.seconds | |
w.pid_file = "/var/run/nginx.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 = 8 | |
c.within = 2.minutes | |
c.transition = :start | |
end | |
end | |
# start if process is not running | |
w.transition(:up, :start) do |on| | |
on.condition(:process_exits) | |
end | |
w.transition(:up, :restart) do |on| | |
on.condition(:http_response_code) do |c| | |
c.host = 'localhost' | |
c.port = 80 | |
c.path = '/monitor.html' | |
c.code_is_not = 200 | |
c.timeout = 10.seconds | |
c.times = [3, 5] | |
end | |
end | |
# lifecycle | |
w.lifecycle do |on| | |
on.condition(:flapping) do |c| | |
c.to_state = [:start, :restart] | |
c.times = 5 | |
c.within = 1.minute | |
c.transition = :unmonitored | |
c.retry_in = 10.minutes | |
c.retry_times = 5 | |
c.retry_within = 2.hours | |
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| | |
w.name = "php-cgi" | |
w.interval = 30.seconds # default | |
w.start = "service php-cgi start" | |
w.stop = "service php-cgi stop" | |
w.restart = "service cgi restart" | |
w.start_grace = 20.seconds | |
w.restart_grace = 20.seconds | |
w.pid_file = "/var/run/#{w.name}.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 = 8 | |
c.within = 2.minutes | |
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 = 1.minute | |
c.transition = :unmonitored | |
c.retry_in = 10.minutes | |
c.retry_times = 5 | |
c.retry_within = 2.hours | |
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
%w{6379}.each do |port| | |
God.watch do |w| | |
w.name = "redis" | |
w.interval = 30.seconds | |
w.start = "service redis start" | |
w.stop = "service redis stop" | |
w.restart = "service redis restart" | |
w.start_grace = 10.seconds | |
w.restart_grace = 10.seconds | |
w.start_if do |start| | |
start.condition(:process_running) do |c| | |
c.interval = 5.seconds | |
c.running = false | |
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
rails_env = ENV['RAILS_ENV'] || "production" | |
rails_root = ENV['RAILS_ROOT'] || "/home/deploy/rails_apps/appname/current" | |
God.watch do |w| | |
w.name = "resque-scheduler" | |
w.group = 'resque' | |
w.interval = 30.seconds | |
w.log = "#{rails_root}/log/#{w.name}.log" | |
w.env = {"QUEUE" => "*", "RAILS_ENV" => rails_env} | |
w.start = "/usr/local/bin/rake -f #{rails_root}/Rakefile environment resque:scheduler" | |
w.start_if do |start| | |
start.condition(:process_running) do |c| | |
c.interval = 5.seconds | |
c.running = false | |
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
rails_env = ENV['RAILS_ENV'] || "production" | |
rails_root = ENV['RAILS_ROOT'] || "/home/deploy/rails_apps/appname/current" | |
num_workers = rails_env == 'production' ? 2 : 1 | |
num_workers.times do |num| | |
God.watch do |w| | |
w.name = "resque-#{num}" | |
w.group = 'resque' | |
w.interval = 30.seconds | |
w.log = "#{rails_root}/log/#{w.name}.log" | |
w.env = {"QUEUE" => "*", "RAILS_ENV" => rails_env} | |
w.start = "/usr/local/bin/rake -f #{rails_root}/Rakefile environment resque:work" | |
w.uid = 'deploy' | |
w.gid = 'deploy' | |
# restart if memory gets too high | |
w.transition(:up, :restart) do |on| | |
on.condition(:memory_usage) do |c| | |
c.above = 350.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 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment