Class: Rudy::Routines::Reboot

Inherits:
Base
  • Object
show all
Defined in:
lib/rudy/routines/reboot.rb

Instance Method Summary collapse

Methods inherited from Base

#enjoy_every_sandwich, #execute_dependency, #generic_machine_runner, #has_remote_task?, #initialize, #keep_going?, #machine_separator, #preliminary_separator, #routine_separator, #task_separator

Methods included from Huxtable

change_environment, change_position, change_region, change_role, change_zone, #check_keys, #config_dirname, create_domain, #current_group_name, #current_machine_address, #current_machine_count, #current_machine_group, #current_machine_hostname, #current_machine_image, #current_machine_name, #current_machine_size, #current_user, #current_user_keypairpath, debug?, #debug?, domain, domain_exists?, #group_metadata, #has_keypair?, #has_keys?, #has_pem_keys?, #has_root_keypair?, keypair_path_to_name, #known_machine_group?, #root_keypairname, #root_keypairpath, #switch_user, update_config, update_global, update_logger, #user_keypairname, #user_keypairpath

Constructor Details

This class inherits a constructor from Rudy::Routines::Base

Instance Method Details

#execute(&each_mach) ⇒ Object

  • each_mach is an optional block which is executed between

disk creation and the after scripts. The will receives two arguments: instances of Rudy::Machine and Rye::Box.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/rudy/routines/reboot.rb', line 13

def execute(&each_mach)
  routine_separator(:reboot)
  unless @routine
    STDERR.puts "[this is a generic reboot routine]"
    @routine = {}
  end
  machines = []
  generic_machine_runner(:list) do |machine,rbox|
    puts $/, "Rebooting...", $/
    rbox.disconnect
    machine.restart
    sleep 4
    msg = preliminary_separator("Checking if instance is running...")
    Rudy::Utils.waiter(3, 120, STDOUT, msg, 0) {
      machine.running?
    } 
  
    # Add instance info to machine and save it. This is really important
    # for the initial startup so the metadata is updated right away. But
    # it's also important to call here because if a routine was executed
    # and an unexpected exception occurs before this update is executed
    # the machine metadata won't contain the DNS information. Calling it
    # here ensure that the metadata is always up-to-date. 
    machine.update 
    
    sleep 4
    
    msg = preliminary_separator("Waiting for SSH daemon...")
    Rudy::Utils.waiter(3, 120, STDOUT, msg, 0) {
      Rudy::Utils.service_available?(machine.dns_public, 22)
    }
    
    # NOTE: THIS IS INCOMPLETE
    
    sleep 1  # Avoid IOError: closed stream on SSH
    
  
    if Rudy::Routines::DiskHelper.disks?(@routine)         # disk
      puts task_separator("DISKS")
      if rbox.ostype == "sunos"
        puts "Sorry, Solaris is not supported yet!"
      else
        Rudy::Routines::DiskHelper.execute(@routine, machine, rbox)
      end    
    end

    machines << machine
  end
  machines
end

#init(*args) ⇒ Object



6
7
8
# File 'lib/rudy/routines/reboot.rb', line 6

def init(*args)
  @routine = fetch_routine_config(:reboot)
end

#raise_early_exceptionsObject

Called by generic_machine_runner



65
66
67
68
69
70
71
# File 'lib/rudy/routines/reboot.rb', line 65

def raise_early_exceptions
  rmach = Rudy::Machines.new
  # There's no keypair check here because Rudy::Machines will attempt 
  # to create one.
  raise MachineGroupNotDefined, current_machine_group unless known_machine_group?
  raise MachineGroupNotRunning, current_machine_group unless rmach.running?
end