ec2launcher 1.1.2 → 1.2.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.
- data/CHANGELOG.md +10 -0
- data/bin/ec2launcher +7 -3
- data/ec2launcher.gemspec +1 -1
- data/lib/ec2launcher/aws_initializer.rb +28 -0
- data/lib/ec2launcher/backoff_runner.rb +1 -1
- data/lib/ec2launcher/dsl/environment.rb +2 -0
- data/lib/ec2launcher/init_options.rb +13 -3
- data/lib/ec2launcher/terminator.rb +53 -0
- data/lib/ec2launcher/version.rb +1 -1
- data/lib/ec2launcher.rb +4 -22
- data/startup-scripts/setup_instance.rb +6 -0
- metadata +7 -4
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 1.2.0
|
2
|
+
|
3
|
+
* Added support for terminating instances.
|
4
|
+
|
5
|
+
## 1.1.3
|
6
|
+
|
7
|
+
* Fixed typo with error handling in BackoffRunner.
|
8
|
+
* Bumped required version of AWS SDK to support IAM Instance Profiles.
|
9
|
+
* Fixed typo with IAM instance profile attribute name.
|
10
|
+
|
1
11
|
## 1.1.2
|
2
12
|
|
3
13
|
* Added support for specifying an IAM Instance Profile through the environment and/or application.
|
data/bin/ec2launcher
CHANGED
@@ -5,7 +5,8 @@
|
|
5
5
|
require 'erb'
|
6
6
|
|
7
7
|
require 'ec2launcher'
|
8
|
-
require
|
8
|
+
require 'ec2launcher/init_options'
|
9
|
+
require 'ec2launcher/terminator'
|
9
10
|
|
10
11
|
opt_parser = EC2Launcher::InitOptions.new
|
11
12
|
opt_parser.parse(ARGV)
|
@@ -25,9 +26,12 @@ if opt_parser.command == "init"
|
|
25
26
|
File.open("config.rb", 'w') {|f| f.write(new_config_template.result)}
|
26
27
|
|
27
28
|
puts "Successfully created #{opt_parser.location}"
|
29
|
+
elsif opt_parser.command =~ /^term/
|
30
|
+
terminator = EC2Launcher::Terminator.new
|
31
|
+
terminator.terminate(opt_parser.hostname, opt_parser.options)
|
28
32
|
elsif opt_parser.command == "launch"
|
29
|
-
|
30
|
-
|
33
|
+
launcher = EC2Launcher::Launcher.new
|
34
|
+
launcher.launch(opt_parser.options)
|
31
35
|
else
|
32
36
|
opt_parser.help
|
33
37
|
exit 1
|
data/ec2launcher.gemspec
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012 Sean Laurent
|
3
|
+
#
|
4
|
+
require 'rubygems'
|
5
|
+
require 'aws-sdk'
|
6
|
+
|
7
|
+
module EC2Launcher
|
8
|
+
module AWSInitializer
|
9
|
+
# Initializes connections to the AWS SDK
|
10
|
+
#
|
11
|
+
def initialize_aws(access_key = nil, secret_key = nil)
|
12
|
+
aws_access_key = access_key
|
13
|
+
aws_access_key ||= ENV['AWS_ACCESS_KEY']
|
14
|
+
|
15
|
+
aws_secret_access_key = secret_key
|
16
|
+
aws_secret_access_key ||= ENV['AWS_SECRET_ACCESS_KEY']
|
17
|
+
|
18
|
+
if aws_access_key.nil? || aws_secret_access_key.nil?
|
19
|
+
abort("You MUST either set the AWS_ACCESS_KEY and AWS_SECRET_ACCESS_KEY environment variables or use the command line options.")
|
20
|
+
end
|
21
|
+
|
22
|
+
AWS.config({
|
23
|
+
:access_key_id => aws_access_key,
|
24
|
+
:secret_access_key => aws_secret_access_key
|
25
|
+
})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -28,7 +28,7 @@ module EC2Launcher
|
|
28
28
|
rescue AWS::EC2::Errors::InstanceLimitExceeded
|
29
29
|
puts "AWS::EC2::Errors::InstanceLimitExceeded ... aborting launch."
|
30
30
|
return false
|
31
|
-
rescue
|
31
|
+
rescue Exception => bang
|
32
32
|
print "Error for #{message}: #{bang}"
|
33
33
|
return false
|
34
34
|
end
|
@@ -12,8 +12,9 @@ module EC2Launcher
|
|
12
12
|
attr_reader :command
|
13
13
|
attr_reader :options
|
14
14
|
attr_reader :location
|
15
|
+
attr_reader :hostname
|
15
16
|
|
16
|
-
SUB_COMMANDS = %w{init launch}
|
17
|
+
SUB_COMMANDS = %w{init launch terminate term}
|
17
18
|
|
18
19
|
def initialize
|
19
20
|
@opts = OptionParser.new do |opts|
|
@@ -21,8 +22,9 @@ module EC2Launcher
|
|
21
22
|
|
22
23
|
where [COMMAND] is one of:
|
23
24
|
|
24
|
-
init [LOCATION]
|
25
|
-
launch [OPTIONS]
|
25
|
+
init [LOCATION] Initialize a repository in the specified directory.
|
26
|
+
launch [OPTIONS] Launch a new instance.
|
27
|
+
terminate [name] [OPTIONS] Terminates an instance.
|
26
28
|
|
27
29
|
and [OPTIONS] include:
|
28
30
|
|
@@ -172,6 +174,14 @@ module EC2Launcher
|
|
172
174
|
exit 1
|
173
175
|
end
|
174
176
|
@location = args[0]
|
177
|
+
elsif @command =~ /^term/
|
178
|
+
unless args.length >= 1
|
179
|
+
puts "Missing name of server!"
|
180
|
+
puts
|
181
|
+
help
|
182
|
+
exit 1
|
183
|
+
end
|
184
|
+
@hostname = args[0]
|
175
185
|
else
|
176
186
|
@opts.parse!(args)
|
177
187
|
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012 Sean Laurent
|
3
|
+
#
|
4
|
+
require 'rubygems'
|
5
|
+
require 'aws-sdk'
|
6
|
+
require 'log4r'
|
7
|
+
|
8
|
+
require 'ec2launcher/aws_initializer'
|
9
|
+
require 'ec2launcher/backoff_runner'
|
10
|
+
|
11
|
+
module EC2Launcher
|
12
|
+
class Terminator
|
13
|
+
include AWSInitializer
|
14
|
+
include BackoffRunner
|
15
|
+
|
16
|
+
def initialize()
|
17
|
+
@log = Logger.new 'ec2launcher'
|
18
|
+
log_output = Outputter.stdout
|
19
|
+
log_output.formatter = PatternFormatter.new :pattern => "%m"
|
20
|
+
@log.outputters = log_output
|
21
|
+
end
|
22
|
+
|
23
|
+
def terminate(server_name, options)
|
24
|
+
##############################
|
25
|
+
# Initialize AWS and create EC2 connection
|
26
|
+
##############################
|
27
|
+
initialize_aws(options.access_key, options.secret)
|
28
|
+
@ec2 = AWS::EC2.new
|
29
|
+
instance = nil
|
30
|
+
AWS.memoize do
|
31
|
+
instances = @ec2.instances.filter("tag:Name", server_name)
|
32
|
+
instances.each do |i|
|
33
|
+
unless i.status == :shutting_down || i.status == :terminated
|
34
|
+
instance = i
|
35
|
+
break
|
36
|
+
end # unless status
|
37
|
+
end # instance loop
|
38
|
+
end # memoize
|
39
|
+
|
40
|
+
if instance
|
41
|
+
@log.info("Terminating instance: #{server_name} [#{instance.instance_id}]")
|
42
|
+
instance.terminate
|
43
|
+
@log.info("Deleting node/client from Chef: #{server_name}")
|
44
|
+
node_result = `echo "Y" |knife node delete #{server_name}`
|
45
|
+
client_result = `echo "Y" |knife client delete #{server_name}`
|
46
|
+
@log.debug("Deleted Chef node: #{result}")
|
47
|
+
@log.debug("Deleted Chef client: #{result}")
|
48
|
+
else
|
49
|
+
@log.error("Unable to find instance: #{server_name}")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/ec2launcher/version.rb
CHANGED
data/lib/ec2launcher.rb
CHANGED
@@ -14,6 +14,7 @@ require 'ec2launcher/dsl/config'
|
|
14
14
|
require 'ec2launcher/dsl/application'
|
15
15
|
require 'ec2launcher/dsl/environment'
|
16
16
|
|
17
|
+
require 'ec2launcher/aws_initializer'
|
17
18
|
require 'ec2launcher/backoff_runner'
|
18
19
|
require 'ec2launcher/instance_paths_config'
|
19
20
|
require 'ec2launcher/block_device_builder'
|
@@ -35,6 +36,7 @@ module EC2Launcher
|
|
35
36
|
end
|
36
37
|
|
37
38
|
class Launcher
|
39
|
+
include AWSInitializer
|
38
40
|
include BackoffRunner
|
39
41
|
|
40
42
|
def initialize()
|
@@ -101,7 +103,7 @@ module EC2Launcher
|
|
101
103
|
##############################
|
102
104
|
# Initialize AWS and create EC2 connection
|
103
105
|
##############################
|
104
|
-
initialize_aws()
|
106
|
+
initialize_aws(@options.access_key, @options.secret)
|
105
107
|
@ec2 = AWS::EC2.new
|
106
108
|
|
107
109
|
##############################
|
@@ -484,26 +486,6 @@ module EC2Launcher
|
|
484
486
|
dns_name.nil? ? "n/a" : dns_name
|
485
487
|
end
|
486
488
|
|
487
|
-
# Initializes connections to the AWS SDK
|
488
|
-
#
|
489
|
-
def initialize_aws()
|
490
|
-
aws_access_key = @options.access_key
|
491
|
-
aws_access_key ||= ENV['AWS_ACCESS_KEY']
|
492
|
-
|
493
|
-
aws_secret_access_key = @options.secret
|
494
|
-
aws_secret_access_key ||= ENV['AWS_SECRET_ACCESS_KEY']
|
495
|
-
|
496
|
-
if aws_access_key.nil? || aws_secret_access_key.nil?
|
497
|
-
abort("You MUST either set the AWS_ACCESS_KEY and AWS_SECRET_ACCESS_KEY environment variables or use the command line options.")
|
498
|
-
end
|
499
|
-
|
500
|
-
@log.info "Initializing AWS connection..."
|
501
|
-
AWS.config({
|
502
|
-
:access_key_id => aws_access_key,
|
503
|
-
:secret_access_key => aws_secret_access_key
|
504
|
-
})
|
505
|
-
end
|
506
|
-
|
507
489
|
# Launches an EC2 instance.
|
508
490
|
#
|
509
491
|
# @param [String] FQDN for the new host.
|
@@ -535,7 +517,7 @@ module EC2Launcher
|
|
535
517
|
launch_mapping[:block_device_mappings] = block_device_mappings
|
536
518
|
end
|
537
519
|
|
538
|
-
launch_mapping[:
|
520
|
+
launch_mapping[:iam_instance_profile] = iam_profile if iam_profile
|
539
521
|
launch_mapping[:subnet] = vpc_subnet if vpc_subnet
|
540
522
|
|
541
523
|
new_instance = @ec2.instances.create(launch_mapping)
|
@@ -367,12 +367,18 @@ end
|
|
367
367
|
# Launch Chef
|
368
368
|
def run_chef_client(chef_path)
|
369
369
|
result = 0
|
370
|
+
last_line = nil
|
370
371
|
Open3.popen3(chef_path) do |stdin, stdout, stderr, wait_thr|
|
371
372
|
stdout.each do |line|
|
373
|
+
last_line = line
|
372
374
|
puts line
|
373
375
|
end
|
374
376
|
result = wait_thr.value if wait_thr
|
375
377
|
end
|
378
|
+
if last_line =~ /[ ]ERROR[:][ ]/
|
379
|
+
result = -1
|
380
|
+
end
|
381
|
+
|
376
382
|
result
|
377
383
|
end
|
378
384
|
|
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.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
21
|
+
version: 1.6.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.
|
29
|
+
version: 1.6.6
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: log4r
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- ec2launcher.gemspec
|
62
62
|
- lib/ec2launcher.rb
|
63
63
|
- lib/ec2launcher/application_processor.rb
|
64
|
+
- lib/ec2launcher/aws_initializer.rb
|
64
65
|
- lib/ec2launcher/backoff_runner.rb
|
65
66
|
- lib/ec2launcher/block_device_builder.rb
|
66
67
|
- lib/ec2launcher/config_loader.rb
|
@@ -78,6 +79,7 @@ files:
|
|
78
79
|
- lib/ec2launcher/init_options.rb
|
79
80
|
- lib/ec2launcher/instance_paths_config.rb
|
80
81
|
- lib/ec2launcher/security_group_handler.rb
|
82
|
+
- lib/ec2launcher/terminator.rb
|
81
83
|
- lib/ec2launcher/version.rb
|
82
84
|
- startup-scripts/runurl
|
83
85
|
- startup-scripts/setup.rb
|
@@ -107,3 +109,4 @@ signing_key:
|
|
107
109
|
specification_version: 3
|
108
110
|
summary: Tool to launch EC2 instances.
|
109
111
|
test_files: []
|
112
|
+
has_rdoc:
|