Skip to content

Instantly share code, notes, and snippets.

@abronte
Created January 5, 2012 00:07
Show Gist options
  • Select an option

  • Save abronte/1562959 to your computer and use it in GitHub Desktop.

Select an option

Save abronte/1562959 to your computer and use it in GitHub Desktop.
Machine checker
#!/usr/bin/ruby
loop do
Machine.all.each do |m|
m.alive?
puts "#{m.name} is #{m.mstatus}"
end
@home = Home.first
@desktop = Machine.find(3)
@server = Machine.find(2)
@adam = Machine.find(1)
@jill = Machine.find(4)
current = Time.now
if (@adam.mstatus == "down" && @jill.mstatus == "down") &&
((current - @adam.last_alive > 15.minutes) || (current - @jill.last_alive > 15.minutes))
if @desktop.mstatus == "up"
@desktop.sleep
end
if @server.mstatus == "up"
@server.sleep
end
elsif (@adam.mstatus == "up" || @jill.mstatus == "up") && !@home.sleeping
if @desktop.mstatus == "down"
@desktop.wake
end
if @server.mstatus == "down"
@server.wake
end
end
@home.save
sleep(10)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment