Last active
October 22, 2015 22:51
-
-
Save RoxasShadow/a68e15613b151380c7e6 to your computer and use it in GitHub Desktop.
This file contains 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
require 'uptimerobot' | |
require 'droplet_kit' | |
require 'rufus-scheduler' | |
include UptimeRobot::Monitor | |
UP_TOKEN = '' | |
DO_TOKEN = '' | |
DROPLET_ID = 0 | |
def restart_droplet! | |
@do_client ||= DropletKit::Client.new(access_token: DO_TOKEN) | |
@do_client.droplet_actions.power_cycle(droplet_id: DROPLET_ID) | |
end | |
def on_droplet_down(&block) | |
@up_client ||= UptimeRobot::Client.new(apiKey: UP_TOKEN) | |
monitor = @up_client.getMonitors['monitors']['monitor'][0] | |
instance_eval(&block) if monitor['status'].to_i != Status::Up | |
end | |
Rufus::Scheduler.s.every '5m' do | |
on_droplet_down { restart_droplet! } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment