Created
June 27, 2011 19:42
-
-
Save clintecker/1049640 to your computer and use it in GitHub Desktop.
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
# 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