solutious-rudy 0.8.5 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. data/CHANGES.txt +55 -14
  2. data/README.rdoc +26 -34
  3. data/Rudyfile +27 -32
  4. data/bin/rudy +47 -27
  5. data/bin/rudy-ec2 +2 -16
  6. data/bin/rudy-s3 +0 -10
  7. data/bin/rudy-sdb +11 -12
  8. data/lib/rudy.rb +49 -89
  9. data/lib/rudy/aws.rb +2 -43
  10. data/lib/rudy/aws/ec2.rb +57 -20
  11. data/lib/rudy/aws/ec2/address.rb +10 -11
  12. data/lib/rudy/aws/ec2/group.rb +10 -9
  13. data/lib/rudy/aws/ec2/image.rb +8 -8
  14. data/lib/rudy/aws/ec2/instance.rb +15 -16
  15. data/lib/rudy/aws/ec2/keypair.rb +14 -19
  16. data/lib/rudy/aws/ec2/snapshot.rb +16 -9
  17. data/lib/rudy/aws/ec2/volume.rb +37 -24
  18. data/lib/rudy/aws/ec2/zone.rb +5 -4
  19. data/lib/rudy/aws/s3.rb +2 -1
  20. data/lib/rudy/aws/sdb.rb +35 -86
  21. data/lib/rudy/backups.rb +24 -0
  22. data/lib/rudy/cli.rb +5 -131
  23. data/lib/rudy/cli/aws/ec2/addresses.rb +19 -27
  24. data/lib/rudy/cli/aws/ec2/candy.rb +32 -7
  25. data/lib/rudy/cli/aws/ec2/groups.rb +9 -13
  26. data/lib/rudy/cli/aws/ec2/images.rb +5 -133
  27. data/lib/rudy/cli/aws/ec2/instances.rb +25 -25
  28. data/lib/rudy/cli/aws/ec2/keypairs.rb +7 -11
  29. data/lib/rudy/cli/aws/ec2/snapshots.rb +5 -9
  30. data/lib/rudy/cli/aws/ec2/volumes.rb +22 -23
  31. data/lib/rudy/cli/aws/ec2/zones.rb +2 -3
  32. data/lib/rudy/cli/aws/sdb/domains.rb +5 -6
  33. data/lib/rudy/cli/aws/sdb/objects.rb +33 -0
  34. data/lib/rudy/cli/aws/sdb/select.rb +23 -0
  35. data/lib/rudy/cli/backups.rb +38 -0
  36. data/lib/rudy/cli/base.rb +98 -0
  37. data/lib/rudy/cli/candy.rb +1 -2
  38. data/lib/rudy/cli/config.rb +7 -4
  39. data/lib/rudy/cli/disks.rb +6 -8
  40. data/lib/rudy/cli/execbase.rb +53 -0
  41. data/lib/rudy/cli/machines.rb +14 -18
  42. data/lib/rudy/cli/metadata.rb +24 -10
  43. data/lib/rudy/cli/routines.rb +31 -5
  44. data/lib/rudy/config.rb +17 -22
  45. data/lib/rudy/config/objects.rb +44 -30
  46. data/lib/rudy/disks.rb +25 -0
  47. data/lib/rudy/exceptions.rb +95 -0
  48. data/lib/rudy/global.rb +46 -23
  49. data/lib/rudy/guidelines.rb +3 -2
  50. data/lib/rudy/huxtable.rb +66 -57
  51. data/lib/rudy/machines.rb +41 -263
  52. data/lib/rudy/metadata.rb +212 -38
  53. data/lib/rudy/metadata/backup.rb +123 -78
  54. data/lib/rudy/metadata/disk.rb +152 -170
  55. data/lib/rudy/metadata/machine.rb +179 -0
  56. data/lib/rudy/mixins.rb +2 -1
  57. data/lib/rudy/mixins/hash.rb +3 -1
  58. data/lib/rudy/mixins/symbol.rb +8 -0
  59. data/lib/rudy/routines.rb +127 -344
  60. data/lib/rudy/routines/base.rb +226 -0
  61. data/lib/rudy/routines/handlers/base.rb +48 -0
  62. data/lib/rudy/routines/handlers/depends.rb +49 -0
  63. data/lib/rudy/routines/handlers/disks.rb +239 -0
  64. data/lib/rudy/routines/handlers/group.rb +42 -0
  65. data/lib/rudy/routines/handlers/host.rb +72 -0
  66. data/lib/rudy/routines/handlers/keypair.rb +70 -0
  67. data/lib/rudy/routines/handlers/machines.rb +15 -0
  68. data/lib/rudy/routines/handlers/script.rb +85 -0
  69. data/lib/rudy/routines/handlers/user.rb +41 -0
  70. data/lib/rudy/routines/passthrough.rb +19 -23
  71. data/lib/rudy/routines/reboot.rb +82 -51
  72. data/lib/rudy/routines/shutdown.rb +61 -14
  73. data/lib/rudy/routines/startup.rb +111 -17
  74. data/lib/rudy/utils.rb +12 -59
  75. data/rudy.gemspec +85 -25
  76. data/tryouts/01_mixins/01_hash_tryouts.rb +20 -0
  77. data/tryouts/10_require_time/10_rudy_tryouts.rb +33 -0
  78. data/tryouts/10_require_time/15_global_tryouts.rb +58 -0
  79. data/tryouts/12_config/10_load_config_tryouts.rb +43 -0
  80. data/tryouts/12_config/20_defaults_tryouts.rb +16 -0
  81. data/tryouts/12_config/30_accounts_tryouts.rb +17 -0
  82. data/tryouts/12_config/40_machines_tryouts.rb +53 -0
  83. data/tryouts/12_config/50_commands_tryouts.rb +17 -0
  84. data/tryouts/12_config/60_routines_tryouts.rb +16 -0
  85. data/tryouts/15_huxtable/10_huxtable_tryouts.rb +47 -0
  86. data/tryouts/15_huxtable/20_user_tryouts.rb +47 -0
  87. data/tryouts/20_simpledb/10_domains_tryouts.rb +36 -0
  88. data/tryouts/20_simpledb/20_objects_tryouts.rb +56 -0
  89. data/tryouts/25_ec2/10_keypairs_tryouts.rb +54 -0
  90. data/tryouts/25_ec2/20_groups_tryouts.rb +56 -0
  91. data/tryouts/25_ec2/21_groups_authorize_address_tryouts.rb +53 -0
  92. data/tryouts/25_ec2/22_groups_authorize_account_tryouts.rb +54 -0
  93. data/tryouts/25_ec2/30_addresses_tryouts.rb +42 -0
  94. data/tryouts/25_ec2/40_volumes_tryouts.rb +53 -0
  95. data/tryouts/25_ec2/50_snapshots_tryouts.rb +75 -0
  96. data/tryouts/26_ec2_instances/10_instance_tryouts.rb +107 -0
  97. data/tryouts/26_ec2_instances/50_images_tryouts.rb +7 -0
  98. data/tryouts/30_metadata/10_include_tryouts.rb +45 -0
  99. data/tryouts/30_metadata/13_object_tryouts.rb +19 -0
  100. data/tryouts/30_metadata/50_disk_tryouts.rb +115 -0
  101. data/tryouts/30_metadata/51_disk_digest_tryouts.rb +24 -0
  102. data/tryouts/30_metadata/53_disk_list_tryouts.rb +35 -0
  103. data/tryouts/30_metadata/56_disk_volume_tryouts.rb +68 -0
  104. data/tryouts/30_metadata/60_backup_tryouts.rb +101 -0
  105. data/tryouts/30_metadata/63_backup_list_tryouts.rb +38 -0
  106. data/tryouts/30_metadata/64_backup_disk_tryouts.rb +65 -0
  107. data/tryouts/30_metadata/66_backup_snapshot_tryouts.rb +76 -0
  108. data/tryouts/30_metadata/70_machine_tryouts.rb +85 -0
  109. data/tryouts/30_metadata/73_machine_list_tryouts.rb +58 -0
  110. data/tryouts/30_metadata/76_machine_instance_tryouts.rb +64 -0
  111. data/tryouts/30_metadata/77_machines_tryouts.rb +45 -0
  112. data/tryouts/40_routines/10_keypair_handler_tryouts.rb +52 -0
  113. data/tryouts/40_routines/11_group_handler_tryouts.rb +36 -0
  114. data/tryouts/80_cli/10_rudyec2_tryouts.rb +8 -0
  115. data/tryouts/80_cli/60_rudy_tryouts.rb +41 -0
  116. data/tryouts/failer +6 -0
  117. data/tryouts/misc/console_tryout.rb +91 -0
  118. data/tryouts/misc/disks_tryout.rb +48 -0
  119. data/tryouts/misc/drydock_tryout.rb +48 -0
  120. data/tryouts/misc/nested_methods.rb +103 -0
  121. data/tryouts/misc/session_tryout.rb +46 -0
  122. data/tryouts/misc/tryouts.rb +33 -0
  123. data/tryouts/misc/usage_tryout.rb +23 -0
  124. metadata +119 -31
  125. data/bin/ird +0 -153
  126. data/lib/rudy/metadata/backups.rb +0 -67
  127. data/lib/rudy/metadata/debug.rb +0 -38
  128. data/lib/rudy/metadata/disks.rb +0 -67
  129. data/lib/rudy/metadata/objectbase.rb +0 -108
  130. data/lib/rudy/routines/helper.rb +0 -76
  131. data/lib/rudy/routines/helpers/dependshelper.rb +0 -34
  132. data/lib/rudy/routines/helpers/diskhelper.rb +0 -403
  133. data/lib/rudy/routines/helpers/scripthelper.rb +0 -197
  134. data/lib/rudy/routines/helpers/userhelper.rb +0 -37
  135. data/support/rudy-ec2-startup +0 -200
@@ -1,197 +0,0 @@
1
- require 'tempfile'
2
-
3
- module Rudy; module Routines;
4
- #--
5
- # TODO: Rename to ShellHelper
6
- #++
7
- module ScriptHelper
8
- include Rudy::Routines::HelperBase # TODO: use trap_rbox_errors
9
- extend self
10
-
11
- @@script_types = [:after, :before, :after_local, :before_local, :script, :script_local]
12
-
13
-
14
- # TODO: refactor using this_method
15
-
16
- def before_local(routine, sconf, rbox, option=nil, argv=nil)
17
- execute_command(:before_local, routine, sconf, 'localhost', rbox, option, argv)
18
- end
19
- def before_local?(routine)
20
- # before_local generally doesn't take a user name like the remote
21
- # before block so we add it here (unless the user did specify it)
22
- routine[:before_local] = {
23
- Rudy.sysinfo.user.to_sym => routine.delete(:before_local)
24
- } if routine[:before_local].is_a?(Proc)
25
- execute_command?(:before_local, routine)
26
- end
27
- def script_local(routine, sconf, rbox, option=nil, argv=nil)
28
- execute_command(:script_local, routine, sconf, 'localhost', rbox, option, argv)
29
- end
30
- def script_local?(routine)
31
- # before_local generally doesn't take a user name like the remote
32
- # before block so we add it here (unless the user did specify it)
33
- routine[:script_local] = {
34
- Rudy.sysinfo.user.to_sym => routine.delete(:script_local)
35
- } if routine[:script_local].is_a?(Proc)
36
- execute_command?(:script_local, routine)
37
- end
38
-
39
- def after_local(routine, sconf, rbox, option=nil, argv=nil)
40
- execute_command(:after_local, routine, sconf, 'localhost', rbox, option, argv)
41
- end
42
- def after_local?(routine)
43
- routine[:after_local] = { # See before_local note
44
- Rudy.sysinfo.user.to_sym => routine.delete(:after_local)
45
- } if routine[:after_local].is_a?(Proc)
46
- execute_command?(:after_local, routine)
47
- end
48
-
49
- def before(routine, sconf, machine, rbox, option=nil, argv=nil)
50
- raise "ScriptHelper: Not a Rudy::Machine" unless machine.is_a?(Rudy::Machine)
51
- execute_command(:before, routine, sconf, machine.name, rbox, option, argv)
52
- end
53
- def before?(routine); execute_command?(:before, routine); end
54
-
55
- def after(routine, sconf, machine, rbox, option=nil, argv=nil)
56
- raise "ScriptHelper: Not a Rudy::Machine" unless machine.is_a?(Rudy::Machine)
57
- execute_command(:after, routine, sconf, machine.name, rbox, option, argv)
58
- end
59
- def after?(routine); execute_command?(:after, routine); end
60
-
61
- def script(routine, sconf, machine, rbox, option=nil, argv=nil)
62
- raise "ScriptHelper: Not a Rudy::Machine" unless machine.is_a?(Rudy::Machine)
63
- execute_command(:script, routine, sconf, machine.name, rbox, option, argv)
64
- end
65
- def script?(routine); execute_command?(:script, routine); end
66
-
67
-
68
- private
69
-
70
- # Does the routine have the requested script type?
71
- # * +timing+ is one of: after, before, after_local, before_local
72
- # * +routine+ a single routine hash (startup, shutdown, etc...)
73
- # Prints notice to STDERR if there's an empty conf hash
74
- def execute_command?(timing, routine)
75
- hasconf = (routine.is_a?(Caesars::Hash) && routine.has_key?(timing))
76
- return false unless hasconf
77
- unless routine[timing].kind_of?(Hash)
78
- STDERR.puts "No user supplied for #{timing} block".color(:red)
79
- choice = Annoy.get_user_input('(S)kip (A)bort: ') || ''
80
- if choice.match(/\AS/i)
81
- return
82
- else
83
- exit 12
84
- end
85
- return false
86
- end
87
- routine[timing].each_pair do |user,proc|
88
- #p [timing, user, proc].join(', ')
89
- if proc.nil? || !proc.is_a?(Proc)
90
- STDERR.puts "Empty #{timing} config for #{user}"
91
- else
92
- return true
93
- end
94
- end
95
- false
96
- end
97
-
98
- # * +timing+ is one of: after, before, after_local, before_local
99
- # * +routine+ a single routine hash (startup, shutdown, etc...)
100
- # * +sconf+ is a config hash from machines config (ignored if nil)
101
- # * +hostname+ machine hostname that we're working on
102
- # * +rbox+ a Rye::Box instance for the machine we're working on
103
- def execute_command(timing, routine, sconf, hostname, rbox, option=nil, argv=nil)
104
- raise "ScriptHelper: Not a Rye::Box" unless rbox.is_a?(Rye::Box)
105
- raise "ScriptHelper: #{timing}?" unless @@script_types.member?(timing)
106
-
107
- # Do we need to run this again? It's called in generic_routine_runner
108
- ##if execute_command?(timing, routine) # i.e. before_local?
109
-
110
- # We need to explicitly add the rm command for rbox so we
111
- # can delete the script config file when we're done. This
112
- # adds the method to this instance of rbox only.
113
- # We give it a funny so we can delete it knowing we're not
114
- # deleting a method added somewhere else.
115
- def rbox.rudy_tmp_rm(*args); cmd('rm', args); end
116
-
117
- original_user = rbox.user
118
- user_blocks = routine[timing] || {}
119
- users = user_blocks.keys
120
- # Root stuff is always run first.
121
- users.unshift(users.delete(:root)) if users.member?(:root)
122
- users.each do |user|
123
- proc = user_blocks[user]
124
-
125
- begin
126
- rbox.switch_user user # does nothing if it's the same user
127
- rbox.connect(false) # does nothing if already connected
128
- rescue Net::SSH::AuthenticationFailed, Net::SSH::HostKeyMismatch => ex
129
- STDERR.puts "Error connecting: #{ex.message}".color(:red)
130
- STDERR.puts "Skipping user #{user}".color(:red)
131
- next
132
- end
133
-
134
- begin
135
- # We define hooks so we can still print each command and its output
136
- # when running the command blocks. NOTE: We only print this in
137
- # verbosity mode. We intentionally set and unset the hooks
138
- # so the other commands (config file copy) don't get printed.
139
- if @@global.verbose > 0
140
- # This block gets called for every command method call.
141
- rbox.pre_command_hook do |cmd, args, user, host|
142
- puts command_separator(rbox.preview_command(cmd, args), user, host)
143
- end
144
- end
145
- if @@global.verbose > 1
146
- # And this one gets called after each command method call.
147
- rbox.post_command_hook do |ret|
148
- puts ' ' << ret.stdout.join("#{$/} ") if !ret.stdout.empty?
149
- print_response(ret)
150
- end
151
- end
152
-
153
- ### EXECUTE THE COMMANDS BLOCK
154
- rbox.batch(option, argv, &proc)
155
-
156
- rescue Rye::CommandError => ex
157
- print_response(ex)
158
- choice = Annoy.get_user_input('(S)kip (R)etry (A)bort: ') || ''
159
- if choice.match(/\AS/i)
160
- return
161
- elsif choice.match(/\AR/i)
162
- retry
163
- else
164
- exit 12
165
- end
166
- rescue Rye::CommandNotFound => ex
167
- STDERR.puts " CommandNotFound: #{ex.message}".color(:red)
168
- STDERR.puts ex.backtrace if Rudy.debug?
169
- choice = Annoy.get_user_input('(S)kip (R)etry (A)bort: ') || ''
170
- if choice.match(/\AS/i)
171
- return
172
- elsif choice.match(/\AR/i)
173
- retry
174
- else
175
- exit 12
176
- end
177
- ensure
178
- rbox.pre_command_hook = nil
179
- rbox.post_command_hook = nil
180
- rbox.enable_safe_mode # In case it was disabled
181
- end
182
-
183
- rbox.cd # reset to home dir
184
- end
185
-
186
- # Return the borrowed rbox instance to the user it was provided with
187
- rbox.switch_user original_user
188
-
189
- ##else
190
- ## puts "Nothing to do"
191
- ##end
192
-
193
-
194
- end
195
- end
196
-
197
- end;end
@@ -1,37 +0,0 @@
1
-
2
- module Rudy; module Routines;
3
- module UserHelper
4
- include Rudy::Routines::HelperBase # TODO: use trap_rbox_errors
5
- extend self
6
-
7
- def adduser?(routine)
8
- (!routine.adduser.nil? && !routine.adduser.to_s.empty?)
9
- end
10
- def adduser(routine, machine, rbox)
11
-
12
- # On Solaris, the user's home directory needs to be specified
13
- # explicitly so we do it for linux too for fun.
14
- homedir = rbox.guess_user_home(routine.adduser.to_s)
15
- args = [:m, :d, homedir, :s, '/bin/bash', routine.adduser.to_s]
16
- puts command_separator(rbox.preview_command(:useradd, args), rbox.user, rbox.host)
17
-
18
- # NOTE: We'll may to use platform specific code here.
19
- # Linux has adduser and useradd commands:
20
- # adduser can prompt for info which we don't want.
21
- # useradd does not prompt (on Debian/Ubuntu at least).
22
- # We need to specify bash b/c the default is /bin/sh
23
- trap_rbox_errors { rbox.useradd(args) }
24
- end
25
-
26
- def authorize?(routine)
27
- (!routine.authorize.nil? && !routine.authorize.to_s.empty?)
28
- end
29
- def authorize(routine, machine, rbox)
30
- puts command_separator(:authorize_keys_remote, rbox.user, rbox.host)
31
- trap_rbox_errors { rbox.authorize_keys_remote(routine.authorize) }
32
- end
33
-
34
-
35
- end
36
-
37
- end; end
@@ -1,200 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- # what: Rudy EC2 startup script
4
- # who: delano@solutious.com
5
- # when: 2009-02-25 (rev: 4)
6
-
7
- # NOTE: This is a prototype version of this script. A cleaner version
8
- # with better documentation is forthcoming.
9
-
10
- # Runs when an ec2 instance startups up.
11
- # Grabs configuration from the run time user data and stores it locally.
12
- # See Rudy::CLI::Machines#start_instance for the expected yaml format.
13
-
14
- # Put this in /etc/init.d. Then:
15
- # * chmod 755 rudy-ec2-startup
16
- # * cd /etc/rc3.d
17
- # * ln -s ../init.d/rudy-ec2-startup S17rudy
18
- # * cd /etc/rc4.d
19
- # * ln -s ../init.d/rudy-ec2-startup S17rudy
20
- # * cd /etc/rc5.d
21
- # * ln -s ../init.d/rudy-ec2-startup S17rudy
22
-
23
- require 'yaml'
24
- require 'resolv'
25
-
26
- LOGFILE = '/var/log/rudy-ec2-startup'
27
- USERDATA = 'http://169.254.169.254/2008-02-01/user-data'
28
- METADATA = 'http://169.254.169.254/2008-02-01/meta-data'
29
-
30
- #LOGFILE = '/tmp/rudy-ec2-startup'
31
- #USERDATA = 'http://127.0.0.1/2008-02-01/user-data'
32
- #METADATA = 'http://127.0.0.1/2008-02-01/meta-data'
33
-
34
- METADATAPARAMS = ['instance-id', 'instance-type']
35
-
36
- Rudy::CONFIG_DIR=File.join('.rudy')
37
- Rudy::CONFIG_FILE=File.join('config')
38
-
39
- module Rudy
40
- module EC2Startup
41
- extend self
42
-
43
- VERSION = 4.freeze
44
-
45
- def process_config
46
- begin
47
- File.unlink(LOGFILE) if File.exists?(LOGFILE)
48
- log "RUDY (rev#{VERSION}) is in the house"
49
-
50
- log "Grabing configuration..."
51
- config_yaml = run("curl -s #{USERDATA}")
52
-
53
- log "Grabing meta-data..."
54
- metadata = get_metadata
55
-
56
- log "Processing metadata..."
57
- METADATAPARAMS.each do |name|
58
- default = name.gsub('instance-', '')
59
- value = (metadata[name] && !metadata[name].empty?) ? metadata[name] : default
60
- log " ---> #{name}: #{value}"
61
- write_to_file("/etc/ec2/#{name}", value, "w")
62
- end
63
-
64
- log "Processing userdata..."
65
-
66
- if !config_yaml || config_yaml.empty?
67
- raise "Nothing to process (did you supply user-data when you created the instance)"
68
- end
69
-
70
- config = YAML::load(config_yaml)
71
- config ||= {}
72
-
73
- # Print to STDOUT and NOT to the log.
74
- # We don't want sensitive config values available in the log
75
- puts "CONFIG: " << config_yaml
76
-
77
- zone = config[:zone] ? config[:zone].to_s.downcase : "zone"
78
- environment = config[:environment] ? config[:environment].to_s.downcase : "env"
79
- role = config[:role] ? config[:role].to_s.downcase : "role"
80
- position = config[:position] ? config[:position].to_s.downcase : "00"
81
-
82
- hostname = [zone, environment, role, position].join('-')
83
- log "Setting hostname: #{hostname}"
84
- `hostname #{hostname}`
85
-
86
- config[:hosts] ||= {}
87
- config[:hosts][hostname] = '127.0.0.1'
88
-
89
- if config[:userdata] && config[:userdata].is_a?(Hash)
90
- # TODO: How to we get the path to any user's home directory?
91
- # (when we're not running as that user.)
92
- config[:userdata].each_pair do |n,hash|
93
- fileparts = (n == :root) ? ['/root'] : [user_home_dir(n)]
94
- fileparts << Rudy::CONFIG_DIR
95
- dirpath = File.join(fileparts)
96
- filepath = File.join(dirpath, Rudy::CONFIG_FILE)
97
-
98
- # Backwards compatability
99
- if !File.directory?(dirpath)
100
- log "Deleting the deprecated #{dirpath} config"
101
- File.unlink(dirpath)
102
- end
103
-
104
- unless File.exists?(dirpath)
105
- log "Creating #{dirpath}"
106
- Dir.mkdir(dirpath, 0700)
107
- end
108
-
109
- log "Writing to #{filepath}"
110
- user_data = {
111
- :userdata => hash
112
- }
113
- write_to_file(filepath, user_data.to_yaml, "w")
114
- end
115
- end
116
-
117
- if config[:hosts] && config[:hosts].is_a?(Hash)
118
- unless read_file('/etc/hosts') =~ /----- RUDY SAYS -----/
119
- log "Updating /etc/hosts..."
120
- write_to_file("/etc/hosts", "\n# ----- RUDY SAYS -----\n", :append)
121
- config[:hosts].each_pair do |name, address|
122
- # Respect existing entries
123
- next if read_file('/etc/hosts') =~ /#{name}/
124
-
125
- ip_address = (address !~ /^\d.+/) ? Resolv.getaddress(address) : address
126
-
127
- log " ---> #{name}: #{ip_address}"
128
- write_to_file("/etc/hosts", "\n#{ip_address}\t#{name}\n", :append)
129
- end
130
- end
131
- end
132
-
133
- log "Done!"
134
-
135
- rescue => ex
136
- log "ERROR: #{ex.message}"
137
- end
138
- end
139
-
140
-
141
- def get_metadata
142
- metadata = {}
143
-
144
- begin
145
- METADATAPARAMS.each do |param|
146
- log " ---> #{param}"
147
- metadata[param.to_s] = run("curl -s #{METADATA}/#{param}")
148
- metadata[param.to_s] = nil if metadata[param.to_s].empty?
149
- end
150
- rescue => ex
151
- log("Problem getting metadata: #{ex.message}")
152
- end
153
- metadata
154
- end
155
-
156
- def run(command, input='')
157
- IO.popen(command, 'r+') do |io|
158
- io.read
159
- end
160
- end
161
-
162
- def get_formatted_time
163
- t = Time.now
164
- t_out = t.strftime("%H:%M:%S%p (%m/%d/%Y)")
165
- end
166
-
167
- def write_to_file(filename, s, type)
168
- type = (type == :append) ? 'a' : 'w'
169
- f = File.open(filename,type)
170
- f.puts s
171
- f.close
172
- end
173
-
174
- def read_file(path)
175
- read_file_to_array(path).join('')
176
- end
177
-
178
- def read_file_to_array(path)
179
- contents = []
180
- return contents unless File.exists?(path)
181
- open(path, 'r') do |l|
182
- contents = l.readlines
183
- end
184
- contents
185
- end
186
-
187
- def user_home_dir(user)
188
- (`su #{user} -c "echo \\$HOME"` || '').chomp
189
- end
190
-
191
- def log(s)
192
- msg = "#{get_formatted_time}: #{s}"
193
- write_to_file(LOGFILE, msg, :append)
194
- puts msg
195
- end
196
-
197
- end
198
- end
199
-
200
- Rudy::EC2Startup.process_config