Skip to content

Instantly share code, notes, and snippets.

@clintecker
Created June 27, 2011 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clintecker/1049640 to your computer and use it in GitHub Desktop.
Save clintecker/1049640 to your computer and use it in GitHub Desktop.
# run with: god -c /var/www/mt/tools/pubqueue_god_script.rb -D
require 'tlsmail'
require 'net/smtp'
require 'openssl'
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
God::Contacts::Email.defaults do |d|
d.from_email = 'tech@arstechnica.com'
d.from_name = 'The Lᴏʀᴅ'
d.delivery_method = :smtp
d.server_host = 'smtp.gmail.com'
d.server_port = 587
d.server_auth = :login
d.server_user = 'tech@arstechnica.com'
d.server_domain = 'mail.arstechnica.com'
d.server_password = File.open(File.expand_path('/home/arstechnica/.gmail_password'),'r').readline.strip
end
God.contact(:email) do |c|
c.name = 'clint'
c.group = 'developers'
c.to_email = 'clint@arstechnica.com'
end
God.contact(:email) do |c|
c.name = 'lee'
c.group = 'developers'
c.to_email = 'lee@arstechnica.com'
end
God.watch do |w|
w.name = "mt-pubqueue"
w.interval = 30.seconds # default
w.dir = '/var/www/mt/'
w.start = "perl ./tools/run-periodic-tasks -daemon -verbose -sleep 5"
w.stop_signal = 'QUIT'
w.stop_timeout = 5.seconds
w.start_grace = 10.seconds
w.restart_grace = 10.seconds
w.log = '/var/log/mt/mt.log'
w.behavior(:clean_pid_file)
w.uid = 'arstechnica'
w.gid = 'arstechnica'
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 = 400.megabytes
c.times = [3, 5] # 3 out of 5 intervals
c.notify = {:contacts => 'developers', :priority => 1, :category => 'CMS'}
end
restart.condition(:cpu_usage) do |c|
c.above = 75.percent
c.times = 5
c.notify = {:contacts => 'developers', :priority => 1, :category => 'CMS'}
end
end
# Notify us if the process fails to begin
w.transition(:up, :start) do |on|
on.condition(:process_exits) do |c|
c.notify = {:contacts => 'developers', :priority => 10, :category => 'CMS'}
end
end
# Notify us if god restarts the queue
w.transition([:start, :restart], :up) do |on|
on.condition(:process_running) do |c|
c.running = true
end
end
# lifecycle
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.retry_in = 10.minutes
c.retry_times = 5
c.retry_within = 2.hours
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment