Created
November 16, 2011 17:13
-
-
Save ik5/1370702 to your computer and use it in GitHub Desktop.
A watchdog for ahn v0.1
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'mail' # gem install mail | |
require 'fileutils' # for 1.8 | |
BASE_PATH = '' # Place your path here for ahn | |
DEAMON = '' # Place the deamon path and name here | |
def send_email | |
ip = get_ip # You should create this code yourself | |
mail = Mail.new | |
mail.to '' # Write who should get the email | |
mail.from '' # who sent it ? | |
mail.subject 'Server crash - restarted it' | |
mail.body 'The server %s had ahn crashed.' % ip | |
mail.add_file "#{BASE_PATH}/log/adhearsion.log" | |
# configure your email settings here | |
mail.delivery_method.settings = {:address => '', | |
:authentication => nil, | |
:enable_starttls_auto => true, | |
:domain => ip, :port => 25, | |
:password => nil, :user_name => nil } | |
mail.deliver | |
rescue | |
end | |
begin | |
pid = File.open("#{BASE_PATH}/adhearsion.pid").read.chomp # if file not exists, it will raise an exception ... | |
Process.kill 0, pid.to_i | |
rescue => e | |
send_email | |
FileUtils.mv("#{BASE_PATH}/log/adhearsion.log", | |
"#{BASE_PATH}/log/adhearsion.log.#{Time.now.strftime('%d%m%Y%H%M%S')}") | |
system("#{DEAMON} restart") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment