sml-rubber 0.9.11 → 0.9.13

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -5,4 +5,3 @@
5
5
  * add scripted failover to generated configs for:
6
6
  * remove web hosts from round robin on web host failure
7
7
  * db failover (promote slave replica? master-master replicas? cluster?)
8
- * make passenger default template instead of mongrel
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.11
1
+ 0.9.13
@@ -9,7 +9,7 @@ namespace :rubber do
9
9
 
10
10
  task :custom_install, :roles => :passenger do
11
11
  rubber.sudo_script 'install_passenger', <<-ENDSCRIPT
12
- if [[ -z `ls /usr/lib/ruby/gems/*/gems/passenger-*/ext/apache2/mod_passenger.so 2> /dev/null` ]]; then
12
+ if [[ -z `ls /usr/lib/ruby/gems/*/gems/passenger-#{rubber_env.passenger_version}/ext/apache2/mod_passenger.so 2> /dev/null` ]]; then
13
13
  echo -en "\n\n\n\n" | passenger-install-apache2-module
14
14
  fi
15
15
  ENDSCRIPT
@@ -76,17 +76,18 @@ module Rubber
76
76
 
77
77
  # The configuration for a single instance
78
78
  class InstanceItem
79
- attr_reader :name, :domain, :instance_id
80
- attr_accessor :roles
79
+ attr_reader :name, :domain, :instance_id, :security_groups
80
+ attr_accessor :roles, :zone
81
81
  attr_accessor :external_host, :external_ip
82
82
  attr_accessor :internal_host, :internal_ip
83
83
  attr_accessor :static_ip, :volumes, :partitions
84
84
 
85
- def initialize(name, domain, roles, instance_id)
85
+ def initialize(name, domain, roles, instance_id, security_group_list=[])
86
86
  @name = name
87
87
  @domain = domain
88
88
  @roles = roles
89
89
  @instance_id = instance_id
90
+ @security_groups = security_group_list
90
91
  end
91
92
 
92
93
  def full_name
@@ -162,7 +162,7 @@ namespace :rubber do
162
162
 
163
163
  logger.info "Instance #{instance_id} created"
164
164
 
165
- instance_item = Rubber::Configuration::InstanceItem.new(instance_alias, env.domain, instance_roles, instance_id)
165
+ instance_item = Rubber::Configuration::InstanceItem.new(instance_alias, env.domain, instance_roles, instance_id, security_groups)
166
166
  rubber_instances.add(instance_item)
167
167
  rubber_instances.save()
168
168
 
@@ -179,6 +179,7 @@ namespace :rubber do
179
179
  instance_item.external_host = instance[:external_host]
180
180
  instance_item.external_ip = instance[:external_ip]
181
181
  instance_item.internal_host = instance[:internal_host]
182
+ instance_item.zone = instance[:zone]
182
183
  rubber_instances.save()
183
184
 
184
185
  # setup amazon elastic ips if configured to do so
@@ -227,14 +228,18 @@ namespace :rubber do
227
228
 
228
229
  env = rubber_cfg.environment.bind(instance_item.role_names, instance_alias)
229
230
 
230
- instance = cloud.describe_instance(instance_item.instance_id).first
231
+ instance = cloud.describe_instances(instance_item.instance_id).first
231
232
 
232
233
  if instance[:state] == "running"
233
234
  logger.info "\nInstance running, fetching hostname/ip data"
234
235
  instance_item.external_host = instance[:external_host]
235
236
  instance_item.external_ip = instance[:external_ip]
236
237
  instance_item.internal_host = instance[:internal_host]
238
+ instance_item.zone = instance[:zone]
237
239
 
240
+ # setup amazon elastic ips if configured to do so
241
+ setup_static_ips
242
+
238
243
  # Need to setup aliases so ssh doesn't give us errors when we
239
244
  # later try to connect to same ip but using alias
240
245
  setup_local_aliases
@@ -246,18 +251,24 @@ namespace :rubber do
246
251
  # so that we can update all aliases
247
252
  task :_get_ip, :hosts => instance_item.external_ip do
248
253
  instance_item.internal_ip = capture(print_ip_command).strip
254
+ rubber_instances.save()
255
+ end
256
+
257
+ # even though instance is running, sometimes ssh hasn't started yet,
258
+ # so retry on connect failure
259
+ begin
260
+ _get_ip
261
+ rescue ConnectionError
262
+ sleep 2
263
+ logger.info "Failed to connect to #{instance_alias} (#{instance_item.external_ip}), retrying"
264
+ retry
249
265
  end
250
- # even though instance is running, we need to give ssh a chance
251
- # to get started
252
- sleep 5
253
- _get_ip
266
+
254
267
 
255
268
  # Add the aliases for this instance to all other hosts
256
269
  setup_remote_aliases
257
270
  setup_dns_aliases
258
271
  end
259
-
260
- rubber_instances.save()
261
272
  end
262
273
 
263
274
 
@@ -98,7 +98,7 @@ namespace :rubber do
98
98
  groups = isolate_groups(groups) if rubber_env.isolate_security_groups
99
99
  group_keys = groups.keys.clone()
100
100
 
101
- # For each group that does already exist in ec2
101
+ # For each group that does already exist in cloud
102
102
  cloud_groups = cloud.describe_security_groups()
103
103
  cloud_groups.each do |cloud_group|
104
104
  group_name = cloud_group[:name]
@@ -108,7 +108,7 @@ namespace :rubber do
108
108
 
109
109
  if group_keys.delete(group_name)
110
110
  # sync rules
111
- logger.debug "Security Group already in ec2, syncing rules: #{group_name}"
111
+ logger.debug "Security Group already in cloud, syncing rules: #{group_name}"
112
112
  group = groups[group_name]
113
113
  rules = group['rules'].clone
114
114
  rule_maps = []
@@ -133,8 +133,8 @@ namespace :rubber do
133
133
  # rules match, don't need to do anything
134
134
  # logger.debug "Rule in sync: #{rule_map.inspect}"
135
135
  else
136
- # rules don't match, remove them from ec2 and re-add below
137
- answer = Capistrano::CLI.ui.ask("Rule '#{rule_map.inspect}' exists in ec2, but not locally, remove from ec2? [y/N]?: ")
136
+ # rules don't match, remove them from cloud and re-add below
137
+ answer = Capistrano::CLI.ui.ask("Rule '#{rule_map.inspect}' exists in cloud, but not locally, remove from cloud? [y/N]?: ")
138
138
  rule_map = Rubber::Util::symbolize_keys(rule_map)
139
139
  if rule_map[:source_group_name]
140
140
  cloud.remove_security_group_rule(group_name, nil, nil, nil, {:name => rule_map[:source_group_name], :account => rule_map[:source_group_account]})
@@ -160,12 +160,12 @@ namespace :rubber do
160
160
  end
161
161
  else
162
162
  # delete group
163
- answer = Capistrano::CLI.ui.ask("Security group '#{group_name}' exists in ec2 but not locally, remove from ec2? [y/N]: ")
163
+ answer = Capistrano::CLI.ui.ask("Security group '#{group_name}' exists in cloud but not locally, remove from cloud? [y/N]: ")
164
164
  cloud.destroy_security_group(group_name) if answer =~ /^y/
165
165
  end
166
166
  end
167
167
 
168
- # For each group that didnt already exist in ec2
168
+ # For each group that didnt already exist in cloud
169
169
  group_keys.each do |group_name|
170
170
  group = groups[group_name]
171
171
  logger.debug "Creating new security group: #{group_name}"
@@ -332,18 +332,18 @@ namespace :rubber do
332
332
  to_install.delete_if {|g, v| installed.has_key?(g) } if gem_cmd == 'install'
333
333
  to_install_ver.delete_if {|g, v| installed.has_key?(g) && installed[g].include?(v) }
334
334
 
335
- # when versions are provided for a gem, rubygems fails unless versions
336
- # are provided for all gems so we need to do the two groups separately
335
+ # rubygems can only do asingle versioned gem at a time so we need
336
+ # to do the two groups separately
337
+ # install versioned ones first so unversioned don't pull in a newer version
338
+ to_install_ver.each do |g, v|
339
+ system "#{cmd} #{g} -v #{v}"
340
+ fail "Unable to install versioned gem #{g}:#{v}" if $?.exitstatus > 0
341
+ end
337
342
  if to_install.size > 0
338
343
  gem_list = to_install.keys.join(' ')
339
344
  system "#{cmd} #{gem_list}"
340
345
  fail "Unable to install gems" if $?.exitstatus > 0
341
346
  end
342
- if to_install_ver.size > 0
343
- gem_list = to_install_ver.collect {|g, v| "#{g} -v #{v}"}.join(' ')
344
- system "#{cmd} #{gem_list}"
345
- fail "Unable to install versioned gems" if $?.exitstatus > 0
346
- end
347
347
 
348
348
  'EOF'
349
349
  ENDSCRIPT
@@ -38,7 +38,7 @@ namespace :rubber do
38
38
  end
39
39
  env = cfg.environment.bind(roles, instance_alias)
40
40
  domain = env.domain
41
- instance = Rubber::Configuration::InstanceItem.new(instance_alias, domain, role_items, 'dummyid')
41
+ instance = Rubber::Configuration::InstanceItem.new(instance_alias, domain, role_items, 'dummyid', ['dummygroup'])
42
42
  instance.external_host = instance.full_name
43
43
  instance.external_ip = "127.0.0.1"
44
44
  instance.internal_host = instance.full_name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sml-rubber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.11
4
+ version: 0.9.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Conway