Created
December 2, 2008 03:43
-
-
Save ryan-allen/30974 to your computer and use it in GitHub Desktop.
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
# a retarded attempt to make a lighttpd monitor, i don't think this ever worked | |
%w(timeout logger).each { |lib| require lib } | |
open '/var/log/lighty-rebooter.log', 'a' do |logfile| | |
@log = Logger.new(logfile) | |
@log.info "Starting up!" | |
logfile.flush | |
loop do | |
begin | |
response = Timeout.timeout 10 do | |
`curl -I http://psdtuts.com` | |
end | |
puts response.inspect | |
if response.include?('couldn\'t connect to host') | |
@log.warn "Server appears down (jesus!), starting lighttpd..." | |
logfile.flush | |
`/etc/init.d/lighttpd start` | |
end | |
rescue Timeout::Error | |
@log.warn "Request timed out (fastcgi chonked?), restarting lighttpd..." | |
logfile.flush | |
`/etc/init.d/lighttpd restart` | |
sleep 5 | |
rescue | |
@log.debug "Uknown exception occurred (sucks...): #{$!.inspect}" | |
logfile.flush | |
else | |
@log.info "All good!" | |
logfile.flush | |
sleep 10 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment