ec2launcher 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
+ ## 1.5.2
2
+
3
+ * Use local copies of runurl, setup.rb and setup_instance.rb instead of pulling them down from GitHub every time.
4
+ * Fixed CLI help.
5
+
1
6
  ## 1.5.1
2
7
 
3
- * Change order for processing environment aliases.
8
+ * Fixed bug with processing environment aliases.
4
9
 
5
10
  ## 1.5.0
6
11
 
@@ -6,7 +6,4 @@ module EC2Launcher
6
6
 
7
7
  AVAILABILITY_ZONES = %w{us-east-1a us-east-1b us-east-1c us-east-1d}
8
8
  INSTANCE_TYPES = %w{m1.small m1.medium m1.large m1.xlarge t1.micro m2.xlarge m2.2xlarge m2.4xlarge c1.medium c1.xlarge cc1.4xlarge cg1.4xlarge}
9
-
10
- RUN_URL_SCRIPT = "https://raw.github.com/StudyBlue/ec2launcher/master/startup-scripts/runurl"
11
- SETUP_SCRIPT = "https://raw.github.com/StudyBlue/ec2launcher/master/startup-scripts/setup.rb"
12
9
  end
@@ -23,6 +23,7 @@ SYNOPSIS
23
23
  ec2launcher [global options] command [command options] [command arguments]
24
24
 
25
25
  COMMANDS
26
+ help - Get information about a command.
26
27
  init - Initialize a new environment/application repository.
27
28
  launch - Launch a new instance.
28
29
  terminate - Terminates an instance.
@@ -133,6 +134,16 @@ EOH
133
134
  opts.on("--volume-size SIZE", Integer, "EBS volume size in GB. Defaults to #{EC2Launcher::DEFAULT_VOLUME_SIZE} GB") do |volume_size|
134
135
  @options.volume_size = volume_size
135
136
  end
137
+
138
+ opts.separator ""
139
+ opts.separator "Miscellaneous:"
140
+
141
+ # No argument, shows at tail. This will print an options summary.
142
+ # Try it and see!
143
+ opts.on_tail("-?", "--help", "Show this message") do
144
+ puts opts
145
+ exit
146
+ end
136
147
  end
137
148
  end
138
149
 
@@ -143,6 +154,16 @@ EOH
143
154
  opts.on("--[no-]snapshot-removal", "Remove EBS snapshots. Defaults to TRUE.") do |removal|
144
155
  @options.snapshot_removal = removal
145
156
  end
157
+
158
+ opts.separator ""
159
+ opts.separator "Miscellaneous:"
160
+
161
+ # No argument, shows at tail. This will print an options summary.
162
+ # Try it and see!
163
+ opts.on_tail("-?", "--help", "Show this message") do
164
+ puts opts
165
+ exit
166
+ end
146
167
  end
147
168
  end
148
169
 
@@ -180,13 +201,24 @@ EOH
180
201
  @options.directory = "./"
181
202
 
182
203
  # Parse global options
183
- @global_options.order!
204
+ begin
205
+ @global_options.order!
206
+ rescue OptionParser::InvalidOption
207
+ puts "Missing command!"
208
+ puts @global_options
209
+ exit 1
210
+ end
211
+
212
+ if ARGV.size < 1
213
+ puts @global_options
214
+ exit 1
215
+ end
184
216
 
185
217
  # Extract the request command
186
218
  @command = ARGV.shift.downcase
187
219
 
188
220
  unless SUB_COMMANDS.include?(@command)
189
- puts "Missing command! " if @command.nil?
221
+ puts "Missing command!" if @command.nil?
190
222
  puts "Invalid command: #{@command}" unless @command.nil? || @command == "-?" || @command == "--help" || @command == "help"
191
223
  puts @global_options
192
224
  exit 1
@@ -208,7 +240,13 @@ EOH
208
240
  end
209
241
 
210
242
  # Parse sub command options
211
- @subcommands[@command].order! if @subcommands.has_key?(@command)
243
+ begin
244
+ @subcommands[@command].order! if @subcommands.has_key?(@command)
245
+ rescue OptionParser::InvalidOption
246
+ puts "Invalid option!"
247
+ puts @global_options
248
+ exit 1
249
+ end
212
250
 
213
251
  if @command == "init"
214
252
  unless args.length >= 1
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
4
  module EC2Launcher
5
- VERSION = "1.5.1"
5
+ VERSION = "1.5.2"
6
6
  end
data/lib/ec2launcher.rb CHANGED
@@ -41,8 +41,12 @@ module EC2Launcher
41
41
  include BackoffRunner
42
42
 
43
43
  def initialize()
44
+ spec = Gem::Specification.find_by_name("ec2launcher")
45
+ @gem_install_dir = spec.gem_dir
46
+ @startup_scripts_dir = File.join(@gem_install_dir, "startup-scripts")
44
47
  @run_url_script_cache = nil
45
48
  @setup_script_cache = nil
49
+ @setup_instance_script_cache = nil
46
50
 
47
51
  @log = Logger.new 'ec2launcher'
48
52
  log_output = Outputter.stdout
@@ -682,6 +686,11 @@ module EC2Launcher
682
686
  cmd
683
687
  end
684
688
 
689
+ def load_and_encode_file(base_path, filename)
690
+ pathname = File.join(base_path, filename)
691
+ `cat #{pathname} |gzip -f |base64`
692
+ end
693
+
685
694
  # Builds the launch scripts that should run on the new instance.
686
695
  #
687
696
  # launch_options = {
@@ -763,13 +772,15 @@ EOF
763
772
 
764
773
  unless @options.skip_setup
765
774
  if @run_url_script_cache.nil?
766
- puts "Downloading runurl script from #{RUN_URL_SCRIPT}"
767
- @run_url_script_cache = `curl -s #{RUN_URL_SCRIPT} |gzip -f |base64`
775
+ @run_url_script_cache = load_and_encode_file(@startup_scripts_dir, "runurl")
768
776
  end
769
777
 
770
778
  if @setup_script_cache.nil?
771
- puts "Downloading setup script from #{SETUP_SCRIPT}"
772
- @setup_script_cache = `curl -s #{SETUP_SCRIPT} |gzip -f |base64`
779
+ @setup_script_cache = load_and_encode_file(@startup_scripts_dir, "setup.rb")
780
+ end
781
+
782
+ if @setup_instance_script_cache.nil?
783
+ @setup_instance_script_cache = load_and_encode_file(@startup_scripts_dir, "setup_instance.rb")
773
784
  end
774
785
 
775
786
  # runurl script
@@ -777,18 +788,26 @@ EOF
777
788
  user_data += @run_url_script_cache
778
789
  user_data += "End-Of-Message"
779
790
 
780
- # setup script
791
+ # setup scripts
781
792
  user_data += "\ncat > /tmp/setup.rb.gz.base64 <<End-Of-Message2\n"
782
793
  user_data += @setup_script_cache
783
794
  user_data += "End-Of-Message2"
784
795
 
796
+ user_data += "\ncat > /tmp/setup_instance.rb.gz.base64 <<End-Of-Message3\n"
797
+ user_data += @setup_instance_script_cache
798
+ user_data += "End-Of-Message3"
799
+
785
800
  user_data += "\nbase64 -d /tmp/runurl.gz.base64 | gunzip > /tmp/runurl"
786
801
  user_data += "\nchmod +x /tmp/runurl"
787
- # user_data += "\nrm -f /tmp/runurl.gz.base64"
802
+ user_data += "\nrm -f /tmp/runurl.gz.base64"
788
803
 
789
804
  user_data += "\nbase64 -d /tmp/setup.rb.gz.base64 | gunzip > /tmp/setup.rb"
790
805
  user_data += "\nchmod +x /tmp/setup.rb"
791
- # user_data += "\nrm -f /tmp/setup.rb.gz.base64"
806
+ user_data += "\nrm -f /tmp/setup.rb.gz.base64"
807
+
808
+ user_data += "\nbase64 -d /tmp/setup_instance.rb.gz.base64 | gunzip > /tmp/setup_instance.rb"
809
+ user_data += "\nchmod +x /tmp/setup_instance.rb"
810
+ user_data += "\nrm -f /tmp/setup_instance.rb.gz.base64"
792
811
 
793
812
  user_data += "\ngem install ec2launcher --no-ri --no-rdoc"
794
813
 
@@ -10,7 +10,6 @@ require 'json'
10
10
  require 'ec2launcher'
11
11
 
12
12
  SETUP_SCRIPT = "setup_instance.rb"
13
- SETUP_SCRIPT_URL = "https://raw.github.com/StudyBlue/ec2launcher/master/startup-scripts//#{SETUP_SCRIPT}"
14
13
 
15
14
  class InitOptions
16
15
  def initialize
@@ -153,8 +152,7 @@ puts "Connecting to Chef ..."
153
152
  puts `#{chef_path}`
154
153
 
155
154
  # Retrieve secondary setup script and run it
156
- puts "Getting role setup script ..."
157
- puts `s3curl.pl --id startup #{SETUP_SCRIPT_URL} > /tmp/#{SETUP_SCRIPT} && chmod +x /tmp/#{SETUP_SCRIPT}`
155
+ puts "Launching role setup script ..."
158
156
  command = "#{ruby_path} /tmp/#{SETUP_SCRIPT} -a #{options.application} -e #{options.environ} -h #{options.hostname} #{setup_json_filename}"
159
157
  command += " -c #{options.clone_host}" unless options.clone_host.nil?
160
158
  command += " 2>&1 > /var/log/cloud-init.log"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: