# 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