Class Rudy::Routines::Startup

  1. lib/rudy/routines/startup.rb

Methods

public instance

  1. execute
  2. init
  3. raise_early_exceptions

Public instance methods

execute ()

Startup routines run in the following order:

  • before dependencies
  • before_local (if present)
  • Startup instances
  • Set hostname
  • all other actions
  • after dependencies
[show source]
    # File lib/rudy/routines/startup.rb, line 22
22:     def execute
23:       
24:       if run?
25:         Rudy::Routines::Handlers::Depends.execute_all @before, @argv
26:         
27:         li " Executing routine: #{@name} ".att(:reverse), ""
28:         ld "[this is a generic routine]" if @routine.empty?
29:         
30:         if @routine.has_key? :before_local
31:           handler = Rudy::Routines.get_handler :local
32:           Rudy::Routines.rescue {
33:             handler.execute(:local, @routine.delete(:before_local), nil, @@lbox, @argv)
34:           }
35:         end
36:         
37:         Rudy::Routines.rescue {
38:           unless Rudy::Routines::Handlers::Group.exists? 
39:             Rudy::Routines::Handlers::Group.create
40:           end
41:           # Run this every startup incase the ip address has changed. 
42:           # If there's an exception it's probably b/c the address is
43:           # already authorized for port 22. 
44:           Rudy::Routines::Handlers::Group.authorize rescue nil
45:         }
46:         
47:         Rudy::Routines.rescue {
48:           unless Rudy::Routines::Handlers::Keypair.exists? 
49:             Rudy::Routines::Handlers::Keypair.create
50:           end
51:         }
52:         
53:       end
54:       
55:       ## li Rudy::Routines.machine_separator(machine.name, machine.awsid)
56:       
57:       # If this is a testrun we won't create new instances
58:       # we'll just grab the list of machines in this group. 
59:       # NOTE: Expect errors if there are no machines.
60:       Rudy::Routines.rescue {
61:         @machines = run? ? Rudy::Machines.create : Rudy::Machines.list
62:         @@rset = Rudy::Routines::Handlers::RyeTools.create_set @machines
63:       }
64:       
65:       
66:       Rudy::Routines.rescue {
67:         if !Rudy::Routines::Handlers::Host.is_running? @@rset
68:           a = @@rset.boxes.select { |box| !box.stash.instance_running? }
69:           raise GroupNotRunning, a
70:         end
71:       }
72:       
73:       # This is important b/c the machines will not 
74:       # have DNS info until after they are running. 
75:       # This will also assign elastic IP addresses. 
76:       Rudy::Routines.rescue { Rudy::Routines::Handlers::Host.update_dns @@rset }
77:       
78:       Rudy::Routines.rescue {
79:         if !Rudy::Routines::Handlers::Host.is_available? @@rset
80:           a = @@rset.boxes.select { |box| !box.stash.instance_available? }
81:           raise GroupNotAvailable, a
82:         end
83:       }
84:       Rudy::Routines.rescue {
85:         Rudy::Routines::Handlers::Host.set_hostname @@rset      
86:       }
87:       
88:       if run?
89:         # This is the meat of the sandwich
90:         Rudy::Routines.runner @routine, @@rset, @@lbox, @argv
91: 
92:         Rudy::Routines.rescue {
93:           Rudy::Routines::Handlers::Depends.execute_all @after, @argv
94:         }
95:         
96:       end
97:       
98:       @machines
99:     end
init (*args)
[show source]
    # File lib/rudy/routines/startup.rb, line 11
11:     def init(*args)
12:       @routine ||= {}
13:     end
raise_early_exceptions ()

Called by generic_machine_runner

[show source]
     # File lib/rudy/routines/startup.rb, line 102
102:     def raise_early_exceptions
103:       raise NoMachinesConfig unless @@config.machines
104:       # There's no keypair check here because Rudy::Machines will create one 
105:       raise MachineGroupNotDefined, current_machine_group unless known_machine_group?
106:         
107:       unless (1..MAX_INSTANCES).member?(current_machine_count)
108:         raise "Instance count must be more than 0, less than #{MAX_INSTANCES}"
109:       end
110:       
111:       # If this is a testrun, we don't create instances anyway so
112:       # it doesn't matter if there are already instances running.
113:       if run? && !@@global.force
114:         if @@global.position.nil?
115:           raise MachineGroupAlreadyRunning, current_machine_group if Rudy::Machines.running?
116:           #raise MachineGroupMetadataExists, current_machine_group if Rudy::Machines.exists?
117:         else
118:           if Rudy::Machines.running? @@global.position
119:             m = Rudy::Machine.new @@global.position
120:             raise MachineAlreadyRunning, m.name 
121:           end
122:         end
123:       end
124:       
125:       if @routine
126:         bad = @routine.keys - @@allowed_actions
127:         raise UnsupportedActions.new(@name, bad) unless bad.empty?
128:       end
129:     end