Skip to content

Instantly share code, notes, and snippets.

@ryan-allen
Created December 2, 2008 03:43
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 ryan-allen/30974 to your computer and use it in GitHub Desktop.
Save ryan-allen/30974 to your computer and use it in GitHub Desktop.
# 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