Skip to content

Instantly share code, notes, and snippets.

@blackknight36
Last active April 12, 2018 18:56
Show Gist options
  • Save blackknight36/4a147c7a6d157e6300f7867442fbee10 to your computer and use it in GitHub Desktop.
Save blackknight36/4a147c7a6d157e6300f7867442fbee10 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
def check_server(url)
@output = %x(httping -c 1 -s -l -m #{url}).split()
return @output[-1].to_i
end
server_url = '<%= @start_page %>'
lock_file = '/tmp/check_http_lock'
# Exit if loop is running.
exit if File.exist?(lock_file)
status = check_server(server_url)
if status == 200
exit 0
else
File.new(lock_file, "w")
system("DISPLAY=:0 zenity --info --text='Site down. Please stand by.' &")
until status == 200
status = check_server(server_url)
sleep 5
end
system('pkill zenity')
system('logger -t check_http_server.rb "server down - restarting graphical-eol-display.service"')
system('systemctl restart graphical-eol-display.service')
File.delete(lock_file)
exit 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment