Skip to content

Instantly share code, notes, and snippets.

@sfgeorge
Created April 12, 2013 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sfgeorge/5374983 to your computer and use it in GitHub Desktop.
Save sfgeorge/5374983 to your computer and use it in GitHub Desktop.
An antiquated god watch for Adhearsion
# 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