Last active
August 29, 2015 14:21
-
-
Save jmscholen/065c762abfae9fc44444 to your computer and use it in GitHub Desktop.
god config
This file contains hidden or 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_ROOT = File.dirname(File.dirname(__FILE__)) | |
RAILS_ENV = "staging" | |
RUBY_PATH = "/home/rails/.rvm/rubies/ruby-1.9.3-p392/bin/ruby"# path of rails user | |
def generic_monitoring(w, options = {}) | |
w.start_if do |start| | |
start.condition(:process_running) do |c| | |
c.interval = 10.seconds | |
c.running = false | |
c.notify = {:contacts => ['team'], :category => 'Start if processing running false'} | |
end | |
end | |
w.restart_if do |restart| | |
restart.condition(:memory_usage) do |c| | |
c.above = options[:memory_limit] | |
c.times = [3, 5] # 3 out of 5 intervals | |
c.notify = {:contacts => ['team'], :category => 'Restart if memory hits limit'} | |
end | |
restart.condition(:cpu_usage) do |c| | |
c.above = options[:cpu_limit] | |
c.times = 5 | |
c.notify = {:contacts => ['team'], :category => 'Restart if CPU hits limit'} | |
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 = :unmonitored | |
c.notify = {:contacts => ['team'], :category => 'Flapping'} | |
c.retry_in = 10.minutes | |
c.retry_times = 5 | |
c.retry_within = 2.hours | |
end | |
end | |
w.transition(:up, :start) do |on| | |
on.condition(:process_exits) do |c| | |
c.notify = {:contacts => ['team'], :category => 'Transition from up to start on process exits'} | |
end | |
end | |
w.transition([:start, :restart], :up) do |on| | |
on.condition(:process_running) do |c| | |
c.running = true | |
c.notify = {:contacts => ['team'], :category => 'Transition from start/restart to up on process running'} | |
end | |
end | |
end | |
God.watch do |w| | |
w.name = 'task-server' | |
w.interval = 30.seconds | |
w.start = "su - rails -c './app/lib/daemons/daemon_runner start' " | |
w.stop = "su - rails -c './app/lib/daemons/daemon_runner stop' " | |
w.start_grace = 10.seconds | |
w.restart_grace = 10.seconds | |
w.pid_file = "#{RAILS_ROOT}/log/daemon_runner.pid" | |
w.log = "#{RAILS_ROOT}/log/god.log" | |
w.behavior(:clean_pid_file) | |
generic_monitoring(w, :cpu_limit => 30.percent, :memory_limit => 100.megabytes) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment