Skip to content

Instantly share code, notes, and snippets.

@house9
Created March 25, 2010 14:48
Show Gist options
  • Save house9/343625 to your computer and use it in GitHub Desktop.
Save house9/343625 to your computer and use it in GitHub Desktop.
namespace :operations do
desc 'Operations: call this from cron job to make sure the site is up and running'
task (:production_ping => :environment) do
# to set up the cron job
# crontab -e
require 'uri'
require 'net/http'
require 'net/https'
message = "Checking site at #{Time.now.strftime("%Y-%m-%d %H:%M:%S %Z")}\n"
message += "Automated check from: " + `hostname`
begin
url = URI.parse('https://www.TODO.com/login')
path = "/login?operations=production_ping"
http = Net::HTTP.new(url.host, 443)
http.use_ssl = true
response = http.get(path, nil)
message += "HTTP Status: #{response.code} for https://#{url.host}#{path}\n"
#puts "RESPONSE: #{response.code}"
#puts response.body
if response.code != "200" then
raise "NOT 200 was #{response.code}"
end
rescue Exception => ex
message += "Failure: #{ex.message}\n"
Notifier.deliver_production_ping_failure('[email protected]', message)
end
# puts message
`echo "#{message}" >> _production_ping_log.txt`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment