ec2launcher 1.0.17 → 1.0.18

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.0.18
2
+
3
+ * Additional command subsitution variables for ruby, gem, chef-client and knife executables.
4
+
1
5
  ## 1.0.17
2
6
 
3
7
  * Added support to substitute the application name and environment name in pre/post commands.
@@ -0,0 +1,31 @@
1
+ #
2
+ # Copyright (c) 2012 Sean Laurent
3
+ #
4
+ module EC2Launcher
5
+ # Holds data about paths to various executables on instances.
6
+ class InstancePathsConfig
7
+ attr_reader :gem_path, :ruby_path, :chef_path, :knife_path
8
+
9
+ def initialize(environment)
10
+ @gem_path = build_path(environment.gem_path, "gem", "/usr/bin/gem")
11
+ @ruby_path = build_path(environment.ruby_path, "ruby", "/usr/bin/ruby")
12
+ @chef_path = build_path(environment.chef_path, "chef-client", "/usr/bin/chef-client")
13
+ @knife_path = build_path(environment.knife_path, "knife", "/usr/bin/knife")
14
+ end
15
+
16
+ private
17
+
18
+ # Builds the path to an executable.
19
+ def build_path(instance_path, executable, default_path)
20
+ app_path = default_path
21
+ unless instance_path.nil?
22
+ if instance_path =~ /#{executable}$/
23
+ app_path = instance_path
24
+ else
25
+ app_path = File.join(instance_path, executable)
26
+ end
27
+ end
28
+ app_path
29
+ end
30
+ end
31
+ end
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
4
  module EC2Launcher
5
- VERSION = "1.0.17"
5
+ VERSION = "1.0.18"
6
6
  end
data/lib/ec2launcher.rb CHANGED
@@ -14,6 +14,7 @@ require 'ec2launcher/dsl/application'
14
14
  require 'ec2launcher/dsl/environment'
15
15
 
16
16
  require 'ec2launcher/backoff_runner'
17
+ require 'ec2launcher/instance_paths_config'
17
18
  require 'ec2launcher/block_device_builder'
18
19
  require 'ec2launcher/hostname_generator'
19
20
 
@@ -117,7 +118,14 @@ module EC2Launcher
117
118
  end
118
119
  @application = @applications[options.application]
119
120
 
121
+ ##############################
122
+ # INSTANCE PATHS
123
+ ##############################
124
+ @instance_paths = EC2Launcher::InstancePathsConfig.new(@environment)
125
+
126
+ ##############################
120
127
  # Initialize AWS and create EC2 connection
128
+ ##############################
121
129
  initialize_aws()
122
130
  @ec2 = AWS::EC2.new
123
131
 
@@ -701,11 +709,28 @@ module EC2Launcher
701
709
  # Given a string containing a command to run, replaces any inline variables.
702
710
  # Supported variables include:
703
711
  # * @APPLICATION@ - name of the application
712
+ # * @APP@ - name of the application
704
713
  # * @ENVIRONMENT@ - name of the environment
714
+ # * @ENV@ - name of the environment
715
+ # * @RUBY@ - Full pathname to the ruby executable
716
+ # * @GEM@ - Full pathname to the gem executable
717
+ # * @CHEF@ - Full pathname to the chef-client executable
718
+ # * @KNIFE@ - Full pathname to the knife executable
705
719
  #
706
720
  # @return [String] command with variables replaced
707
721
  def substitute_command_variables(cmd)
708
- cmd.gsub(/@APPLICATION@/, @application.name).gsub(/@ENVIRONMENT@/, @environment.name)
722
+ substitutions = {
723
+ /@APPLICATION@/ => @application.name,
724
+ /@APP@/ => @application.name,
725
+ /@ENVIRONMENT@/ => @environment.name,
726
+ /@ENV@/ => @environment.name,
727
+ /@RUBY@/ => @instance_paths.ruby_path,
728
+ /@GEM@/ => @instance_paths.gem_path,
729
+ /@CHEF@/ => @instance_paths.chef_path,
730
+ /@KNIFE@/ => @instance_paths.knife_path
731
+ }
732
+ substitutions.keys.each {|key| cmd.gsub!(key, substitutions[key]) }
733
+ cmd
709
734
  end
710
735
 
711
736
  # Validates all settings in an application file
@@ -757,10 +782,10 @@ module EC2Launcher
757
782
  'gems' => gems,
758
783
  'packages' => packages
759
784
  }
760
- setup_json["gem_path"] = build_path(@environment.gem_path, "gem", "/usr/bin/gem")
761
- setup_json["ruby_path"] = build_path(@environment.ruby_path, "ruby", "/usr/bin/ruby")
762
- setup_json["chef_path"] = build_path(@environment.chef_path, "chef-client", "/usr/bin/chef-client")
763
- setup_json["knife_path"] = build_path(@environment.knife_path, "knife", "/usr/bin/knife")
785
+ setup_json["gem_path"] = @instance_paths.gem_path
786
+ setup_json["ruby_path"] = @instance_paths.ruby_path
787
+ setup_json["chef_path"] = @instance_paths.chef_path
788
+ setup_json["knife_path"] = @instance_paths.knife_path
764
789
 
765
790
  unless @application.block_devices.nil? || @application.block_devices.empty?
766
791
  setup_json['block_devices'] = @application.block_devices
@@ -183,7 +183,7 @@ end
183
183
  ##############################
184
184
  # Assembles a set of existing partitions into a RAID array.
185
185
  def assemble_raid_array(partition_list, raid_device = '/dev/md0', raid_type = 0)
186
- mylog.info "Assembling cloned RAID-#{raid_type.to_s} array #{raid_device} ..."
186
+ puts "Assembling cloned RAID-#{raid_type.to_s} array #{raid_device} ..."
187
187
  command = "/sbin/mdadm --assemble #{raid_device} #{partition_list.join(' ')}"
188
188
  puts command
189
189
  puts `#{command}`
@@ -205,7 +205,18 @@ def setup_attached_raid_array(system_arch, devices, raid_device = '/dev/md0', ra
205
205
 
206
206
  # RAID device name can be a symlink on occasion, so we
207
207
  # want to de-reference the symlink to keep everything clear.
208
- raid_info = `/sbin/mdadm --detail --scan`.split("\n")[-1].split()
208
+ raid_info = "/dev/md0"
209
+ raid_scan_info = `/sbin/mdadm --detail --scan 2>&1`
210
+ puts "RAID Scan Info: #{raid_scan_info}"
211
+ if raid_scan_info =~ /cannot open/
212
+ # This happens occasionally on CentOS 6:
213
+ # $ /sbin/mdadm --detail --scan
214
+ # mdadm: cannot open /dev/md/0_0: No such file or directory
215
+ # mdadm: cannot open /dev/md/1_0: No such file or directory
216
+ raid_info = `ll /dev/md/0_0 |grep -v "md-device-map" |awk '// { print $9; }' |sort`.split("\n")[-1]
217
+ else
218
+ raid_info = raid_scan_info.split("\n")[-1].split()
219
+ end
209
220
  Pathname.new(raid_info[1]).realpath.to_s
210
221
  end
211
222
 
@@ -257,6 +268,16 @@ end
257
268
 
258
269
  # Process EBS volumes
259
270
  unless instance_data["block_devices"].nil?
271
+ # Install mdadm if we have any RAID devices
272
+ raid_required = false
273
+ instance_data["block_devices"].each do |block_device_json|
274
+ unless block_device_json["raid_level"].nil?
275
+ raid_required = true
276
+ break
277
+ end
278
+ end
279
+ puts `yum install mdadm -y` if raid_required
280
+
260
281
  next_device_name = "xvdj"
261
282
  instance_data["block_devices"].each do |block_device_json|
262
283
  if block_device_json["raid_level"].nil?
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.0.17
4
+ version: 1.0.18
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-08-02 00:00:00.000000000 Z
12
+ date: 2012-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -54,6 +54,7 @@ files:
54
54
  - lib/ec2launcher/dsl/environment.rb
55
55
  - lib/ec2launcher/hostname_generator.rb
56
56
  - lib/ec2launcher/init_options.rb
57
+ - lib/ec2launcher/instance_paths_config.rb
57
58
  - lib/ec2launcher/security_group_handler.rb
58
59
  - lib/ec2launcher/version.rb
59
60
  - startup-scripts/setup.rb