-
-
Save ik5/11302623 to your computer and use it in GitHub Desktop.
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
# run with: rvmsudo god -c /srv/phone/phonzy/current/ahn/config/god/adhearsion.god | |
# debug with: rvmsudo god quit && rvmsudo god -c /srv/phone/phonzy/current/ahn/config/god/adhearsion.god -D | |
@deploy_path = '/srv/phone/phonzy' | |
@shared_path = File.join @deploy_path, 'shared' | |
@app_path = File.join @deploy_path, 'current', 'ahn' | |
@log_path = File.join @shared_path, 'log' | |
@pid_path = File.join @shared_path, 'pids' | |
@pid_file = File.join @pid_path, 'adhearsion.pid' | |
@god_env = YAML.load_file("#{@shared_path}/config/god_environment.yml") | |
def ahnctl_command(action = 'daemon') | |
"cd #{@app_path} && bundle exec ahn #{action} . --pid-file=#{@pid_file} >> #{@log_path}/ahnctl_command.log 2>&1" | |
end | |
God.watch do |w| | |
w.name = "phonzy-adhearsion" | |
w.group = "phonzy" | |
w.env = @god_env['environment'] | |
w.interval = 30.seconds | |
w.start_grace = 20.seconds | |
w.restart_grace = 20.seconds | |
w.dir = @app_path | |
w.start = ahnctl_command 'daemon' | |
w.stop = ahnctl_command :stop | |
w.restart = ahnctl_command :restart | |
w.pid_file = @pid_file | |
w.behavior :clean_pid_file | |
w.uid = "phonzy" | |
w.gid = "phonzy" | |
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 = 1.gigabyte | |
c.times = [3, 5] # 3 out of 5 intervals | |
c.notify = {:contacts => ['support'], :priority => 1, :category => 'adhearsion'} | |
end | |
restart.condition(:cpu_usage) do |c| | |
c.above = 80.percent | |
c.times = 5 | |
c.notify = {:contacts => ['support'], :priority => 1, :category => 'adhearsion'} | |
end | |
end | |
w.lifecycle do |on| | |
on.condition(:flapping) do |c| | |
c.to_state = [:start, :restart] | |
c.times = 5 | |
c.within = 5.minute | |
c.notify = {:contacts => ['support'], :priority => 1, :category => 'adhearsion'} | |
c.transition = :unmonitored | |
c.retry_in = 10.minutes | |
c.retry_times = 5 | |
c.retry_within = 2.hours | |
end | |
on.condition(:cpu_usage) do |c| | |
c.above = 40.percent | |
c.times = 5 | |
c.notify = {:contacts => ['support'], :priority => 4, :category => 'adhearsion'} | |
end | |
on.condition(:memory_usage) do |c| | |
c.above = 150.megabytes | |
c.notify = {:contacts => ['support'], :priority => 4, :category => 'adhearsion'} | |
end | |
end | |
w.transition(:up, :start) do |on| | |
on.condition(:process_exits) do |c| | |
c.notify = {:contacts => ['support'], :priority => 1, :category => 'adhearsion'} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment