Skip to content

Instantly share code, notes, and snippets.

@RoxasShadow
Last active October 22, 2015 22:51
Show Gist options
  • Save RoxasShadow/a68e15613b151380c7e6 to your computer and use it in GitHub Desktop.
Save RoxasShadow/a68e15613b151380c7e6 to your computer and use it in GitHub Desktop.
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