capistrano-autoscaling 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +69 -1
- data/lib/capistrano-autoscaling.rb +121 -32
- data/lib/capistrano-autoscaling/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -42,7 +42,75 @@ To enable this recipe, add following in your `config/deploy.rb`.
|
|
42
42
|
after "deploy:rollback", "autoscaling:update"
|
43
43
|
after "autoscaling:update", "autoscaling:cleanup"
|
44
44
|
|
45
|
-
|
45
|
+
The following options are preserved to manage AutoScaling.
|
46
|
+
|
47
|
+
### General options:
|
48
|
+
|
49
|
+
* `:autoscaling_region` - The region name of AWS.
|
50
|
+
* `:autoscaling_access_key_id` - The access key of AWS. By default, find one from `:aws_access_key_id` and `ENV["AWS_ACCESS_KEY_ID"]`.
|
51
|
+
* `:autoscaling_secret_access_key` - The secret access key of AWS. By default, find one from `:aws_secret_access_key` and `ENV["AWS_SECRET_ACCESS_KEY"]`.
|
52
|
+
* `:autoscaling_log_level` - The log level for AWS SDK.
|
53
|
+
* `:autoscaling_application` - The basename for AutoScaling configurations. By default, generate from `:application`.
|
54
|
+
* `:autoscaling_availability_zones` - The availability zones which will be used with AutoScaling. By default, use all availability zones within specified region.
|
55
|
+
* `:autoscaling_instance_type` - The instance type which will be used with AutoScaling. By default, use `t1.micro`.
|
56
|
+
* `:autoscaling_security_groups` - The security groups which will be used with AutoScaling. By default, use `%w(default)`.
|
57
|
+
* `:autoscaling_min_size` - The minimal size of AutoScaling cluster. By default, use `1`.
|
58
|
+
* `:autoscaling_max_size` - The maximum size of AutoScaling cluster. By default, use `:autoscaling_min_size`.
|
59
|
+
|
60
|
+
### ELB options
|
61
|
+
|
62
|
+
* `:autoscaling_create_elb` - Controls whether create new ELB or not. By defalut, `true`.
|
63
|
+
* `:autoscaling_elb_instance` - The ELB instance. By default, create new ELB instance if `:autoscaling_create_elb` is true.
|
64
|
+
* `:autoscaling_elb_listeners` - A Hash of the listener configuration for ELB. By default, generate from `:autoscaling_elb_port` and `:autoscaling_elb_protocol`.
|
65
|
+
* `:autoscaling_elb_port` - The ELB port. By default, use `80`.
|
66
|
+
* `:autoscaling_elb_protocol` - The ELB protocol. By default, use `:http`.
|
67
|
+
* `:autoscaling_elb_instance_port` - The instance port behind ELB. By default, use `:autoscaling_elb_port`.
|
68
|
+
* `:autoscaling_elb_instance_protocol` - The instance protocol behind ELB. By default, use `:autoscaling_elb_protocol`.
|
69
|
+
* `:autoscaling_elb_healthy_threshold` - The healthy threshold of ELB. By default, use `10`.
|
70
|
+
* `:autoscaling_elb_unhealthy_threshold` - The unhealthy threshold of ELB. By default, use `2`.
|
71
|
+
* `:autoscaling_elb_health_check_interval` - The health check interval of ELB. By default, use `30`.
|
72
|
+
* `:autoscaling_elb_health_check_timeout` - The health check timeout of ELB. By default, use `5`.
|
73
|
+
* `:autoscaling_elb_health_check_target` - The health check target of ELB. By default, generate from first listener in `:autoscaling_elb_listeners`.
|
74
|
+
* `:autoscaling_elb_health_check_target_path` - The health check target path for HTTP services. By default, use `"/"`.
|
75
|
+
|
76
|
+
### EC2 options
|
77
|
+
|
78
|
+
* `:autoscaling_ec2_instances` - The EC2 instances behind ELB.
|
79
|
+
* `:autoscaling_ec2_instance_dns_names` - The DNS name of EC2 instances behind ELB.
|
80
|
+
* `:autoscaling_ec2_instance_private_dns_names` - The private DNS name of EC2 instances behind ELB.
|
81
|
+
|
82
|
+
### AMI options
|
83
|
+
|
84
|
+
* `:autoscaling_create_image` - Controls whether create new AMI or not. By default, `true`.
|
85
|
+
* `:autoscaling_image` - The AMI of application. By default, create new AMI if `:autoscaling_create_image` is true.
|
86
|
+
* `:autoscaling_image_extra_options` - The extra options for creating new AMIs.
|
87
|
+
* `:autoscaling_keep_images` - How many AMIs do you want to keep on `autoscaling:cleanup` task. By default, keep 2 AMIs.
|
88
|
+
|
89
|
+
### LaunchConfiguration options
|
90
|
+
|
91
|
+
* `:autoscaling_create_launch_configuration` - Controls whether create new launch configuration or not.
|
92
|
+
* `:autoscaling_launch_configuration` - The launch configuration of application. By default, create new launch configuration if `:autoscaling_create_launch_configuration` is true.
|
93
|
+
* `:autoscaling_launch_configuration_extra_options` - The extra options for creating new launch configurations.
|
94
|
+
|
95
|
+
### AutoScalingGroup options
|
96
|
+
|
97
|
+
* `:autoscaling_create_group` - Controls whether create new group or not. By default, `true`.
|
98
|
+
* `:autoscaling_group` - The group for application. By default, create new group if `:autoscaling_create_group` is true.
|
99
|
+
* `:autoscaling_group_extra_options` - The extra options for creating new group.
|
100
|
+
|
101
|
+
### ScalingPolicy options
|
102
|
+
|
103
|
+
* `:autoscaling_create_policy` - Controls whether create new policies or not.
|
104
|
+
* `:autoscaling_expand_policy` - The scale-out policy.
|
105
|
+
* `:autoscaling_shrink_policy` - The scale-in policy.
|
106
|
+
* `:autoscaling_expand_policy_adjustment` - The scale-out adjustment. By defualt, use `1`.
|
107
|
+
* `:autoscaling_shrink_policy_adjustment` - The scale-in adjustment. By default, use `-1`.
|
108
|
+
|
109
|
+
### MetricAlarm options
|
110
|
+
|
111
|
+
* `:autoscaling_create_alarm` - Controls whether create new alarms or not.
|
112
|
+
* `:autoscaling_expand_alarm_definitions` - The definition of scale-out alarms.
|
113
|
+
* `:autoscaling_shrink_alarm_definitions` - The definition of scale-in alarms.
|
46
114
|
|
47
115
|
|
48
116
|
## Contributing
|
@@ -87,6 +87,7 @@ module Capistrano
|
|
87
87
|
_cset(:autoscaling_application) { autoscaling_name_mangling(application) }
|
88
88
|
_cset(:autoscaling_timestamp) { Time.now.strftime("%Y%m%d%H%M%S") }
|
89
89
|
_cset(:autoscaling_availability_zones) { autoscaling_ec2_client.availability_zones.to_a.map { |az| az.name } }
|
90
|
+
_cset(:autoscaling_subnets, nil) # VPC only
|
90
91
|
_cset(:autoscaling_wait_interval, 1.0)
|
91
92
|
_cset(:autoscaling_keep_images, 2)
|
92
93
|
_cset(:autoscaling_instance_type, "t1.micro")
|
@@ -111,22 +112,36 @@ module Capistrano
|
|
111
112
|
_cset(:autoscaling_elb_instance_name_prefix, "elb-")
|
112
113
|
_cset(:autoscaling_elb_instance_name) { "#{autoscaling_elb_instance_name_prefix}#{autoscaling_application}" }
|
113
114
|
_cset(:autoscaling_elb_instance) { autoscaling_elb_client.load_balancers[autoscaling_elb_instance_name] }
|
115
|
+
_cset(:autoscaling_elb_port, 80)
|
116
|
+
_cset(:autoscaling_elb_protocol, :http)
|
114
117
|
_cset(:autoscaling_elb_listeners) {
|
115
118
|
[
|
116
119
|
{
|
117
|
-
:port =>
|
118
|
-
:protocol =>
|
119
|
-
:instance_port => fetch(:autoscaling_elb_instance_port,
|
120
|
-
:instance_protocol => fetch(:autoscaling_elb_instance_protocol,
|
120
|
+
:port => autoscaling_elb_port,
|
121
|
+
:protocol => autoscaling_elb_protocol,
|
122
|
+
:instance_port => fetch(:autoscaling_elb_instance_port, autoscaling_elb_port),
|
123
|
+
:instance_protocol => fetch(:autoscaling_elb_instance_protocol, autoscaling_elb_protocol),
|
121
124
|
},
|
122
125
|
]
|
123
126
|
}
|
124
127
|
_cset(:autoscaling_elb_availability_zones) { autoscaling_availability_zones }
|
128
|
+
_cset(:autoscaling_elb_subnets) { autoscaling_subnets } # VPC only
|
129
|
+
_cset(:autoscaling_elb_security_groups) { autoscaling_security_groups } # VPC only
|
130
|
+
_cset(:autoscaling_elb_scheme, "internal") # VPC only
|
125
131
|
_cset(:autoscaling_elb_instance_options) {
|
126
|
-
{
|
127
|
-
:availability_zones => autoscaling_elb_availability_zones,
|
132
|
+
options = {
|
128
133
|
:listeners => autoscaling_elb_listeners,
|
129
|
-
}
|
134
|
+
}
|
135
|
+
if autoscaling_elb_subnets and not autoscaling_elb_subnets.empty?
|
136
|
+
# VPC
|
137
|
+
options[:subnets] = autoscaling_elb_subnets
|
138
|
+
options[:security_groups] = autoscaling_elb_security_groups
|
139
|
+
options[:scheme] = autoscaling_elb_scheme
|
140
|
+
else
|
141
|
+
# non-VPC
|
142
|
+
options[:availability_zones] = autoscaling_elb_availability_zones
|
143
|
+
end
|
144
|
+
options.merge(fetch(:autoscaling_elb_instance_extra_options, {}))
|
130
145
|
}
|
131
146
|
_cset(:autoscaling_elb_health_check_target_path, "/")
|
132
147
|
_cset(:autoscaling_elb_health_check_target) {
|
@@ -188,21 +203,31 @@ module Capistrano
|
|
188
203
|
_cset(:autoscaling_launch_configuration_name_prefix, "lc-")
|
189
204
|
_cset(:autoscaling_launch_configuration_name) { "#{autoscaling_launch_configuration_name_prefix}#{autoscaling_image_name}" }
|
190
205
|
_cset(:autoscaling_launch_configuration_instance_type) { autoscaling_instance_type }
|
206
|
+
_cset(:autoscaling_launch_configuration_security_groups) { autoscaling_security_groups }
|
191
207
|
_cset(:autoscaling_launch_configuration_options) {
|
192
208
|
{
|
193
|
-
:security_groups =>
|
209
|
+
:security_groups => autoscaling_launch_configuration_security_groups,
|
194
210
|
}.merge(fetch(:autoscaling_launch_configuration_extra_options, {}))
|
195
211
|
}
|
196
212
|
|
197
213
|
## AutoScalingGroup
|
198
214
|
_cset(:autoscaling_group_name_prefix, "asg-")
|
199
215
|
_cset(:autoscaling_group_name) { "#{autoscaling_group_name_prefix}#{autoscaling_application}" }
|
216
|
+
_cset(:autoscaling_group_availability_zones) { autoscaling_availability_zones }
|
217
|
+
_cset(:autoscaling_group_subnets) { autoscaling_subnets } # VPC only
|
200
218
|
_cset(:autoscaling_group_options) {
|
201
|
-
{
|
202
|
-
:availability_zones => fetch(:autoscaling_group_availability_zones, autoscaling_availability_zones),
|
219
|
+
options = {
|
203
220
|
:min_size => fetch(:autoscaling_group_min_size, autoscaling_min_size),
|
204
221
|
:max_size => fetch(:autoscaling_group_max_size, autoscaling_max_size),
|
205
|
-
}
|
222
|
+
}
|
223
|
+
if autoscaling_group_subnets and not autoscaling_group_subnets.empty?
|
224
|
+
# VPC
|
225
|
+
options[:subnets] = autoscaling_group_subnets
|
226
|
+
else
|
227
|
+
# non-VPC
|
228
|
+
options[:availability_zones] = autoscaling_group_availability_zones
|
229
|
+
end
|
230
|
+
options.merge(fetch(:autoscaling_group_extra_options, {}))
|
206
231
|
}
|
207
232
|
_cset(:autoscaling_group) { autoscaling_autoscaling_client.groups[autoscaling_group_name] }
|
208
233
|
|
@@ -211,11 +236,13 @@ module Capistrano
|
|
211
236
|
_cset(:autoscaling_shrink_policy_name_prefix, "shrink-")
|
212
237
|
_cset(:autoscaling_expand_policy_name) { "#{autoscaling_expand_policy_name_prefix}#{autoscaling_application}" }
|
213
238
|
_cset(:autoscaling_shrink_policy_name) { "#{autoscaling_shrink_policy_name_prefix}#{autoscaling_application}" }
|
214
|
-
_cset(:autoscaling_expand_policy_options) {
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
239
|
+
_cset(:autoscaling_expand_policy_options) {
|
240
|
+
{
|
241
|
+
:adjustment => fetch(:autoscaling_expand_policy_adjustment, 1),
|
242
|
+
:cooldown => fetch(:autoscaling_expand_policy_cooldown, 300),
|
243
|
+
:type => fetch(:autoscaling_expand_policy_type, "ChangeInCapacity"),
|
244
|
+
}.merge(fetch(:autoscaling_expand_policy_extra_options, {}))
|
245
|
+
}
|
219
246
|
_cset(:autoscaling_shrink_policy_options) {
|
220
247
|
{
|
221
248
|
:adjustment => fetch(:autoscaling_shrink_policy_adjustment, -1),
|
@@ -264,14 +291,35 @@ module Capistrano
|
|
264
291
|
|
265
292
|
desc("Setup AutoScaling.")
|
266
293
|
task(:setup, :roles => :app, :except => { :no_release => true }) {
|
267
|
-
|
294
|
+
update_elb
|
295
|
+
}
|
296
|
+
|
297
|
+
desc("Remove AutoScaling settings.")
|
298
|
+
task(:destroy, :roles => :app, :except => { :no_release => true }) {
|
299
|
+
destroy_alarm
|
300
|
+
destroy_policy
|
301
|
+
destroy_group
|
302
|
+
destroy_elb
|
303
|
+
}
|
304
|
+
|
305
|
+
desc("Register current instance for AutoScaling.")
|
306
|
+
task(:update, :roles => :app, :except => { :no_release => true }) {
|
307
|
+
suspend
|
308
|
+
update_image
|
309
|
+
update_launch_configuration
|
310
|
+
update_group
|
311
|
+
update_policy
|
312
|
+
update_alarm
|
313
|
+
resume
|
268
314
|
}
|
269
315
|
|
270
|
-
task(:
|
316
|
+
task(:update_elb, :roles => :app, :except => { :no_release => true }) {
|
271
317
|
if autoscaling_create_elb
|
272
318
|
if autoscaling_elb_instance and autoscaling_elb_instance.exists?
|
273
319
|
logger.debug("Found ELB: #{autoscaling_elb_instance.name}")
|
274
|
-
|
320
|
+
if autoscaling_elb_instance_options.has_key?(:availability_zones)
|
321
|
+
autoscaling_elb_instance.availability_zones.enable(*autoscaling_elb_instance_options[:availability_zones])
|
322
|
+
end
|
275
323
|
autoscaling_elb_listeners.each do |listener|
|
276
324
|
autoscaling_elb_instance.listeners.create(listener)
|
277
325
|
end
|
@@ -290,19 +338,15 @@ module Capistrano
|
|
290
338
|
end
|
291
339
|
}
|
292
340
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
update_launch_configuration
|
303
|
-
update_group
|
304
|
-
update_policy
|
305
|
-
resume
|
341
|
+
task(:destroy_elb, :roles => :app, :except => { :no_release => true }) {
|
342
|
+
if autoscaling_elb_instance and autoscaling_elb_instance.exists?
|
343
|
+
if 0 < autoscaling_elb_instance.length
|
344
|
+
abort("ELB is not empty.")
|
345
|
+
end
|
346
|
+
logger.debug("Deleting ELB: #{autoscaling_elb_instance.name}")
|
347
|
+
autoscaling_elb_instance.delete()
|
348
|
+
logger.debug("Deleted ELB: #{autoscaling_elb_instance.name}")
|
349
|
+
end
|
306
350
|
}
|
307
351
|
|
308
352
|
task(:update_image, :roles => :app, :except => { :no_release => true }) {
|
@@ -373,6 +417,17 @@ module Capistrano
|
|
373
417
|
end
|
374
418
|
}
|
375
419
|
|
420
|
+
task(:destroy_group, :roles => :app, :except => { :no_release => true }) {
|
421
|
+
if autoscaling_group and autoscaling_group.exists?
|
422
|
+
if 0 < autoscaling_elb_instance.instances.length
|
423
|
+
abort("AutoScalingGroup is not empty.")
|
424
|
+
end
|
425
|
+
logger.debug("Deleting AutoScalingGroup: #{autoscaling_group.name} (#{autoscaling_group.launch_configuration_name})")
|
426
|
+
autoscaling_group.delete()
|
427
|
+
logger.debug("Deleted AutoScalingGroup: #{autoscaling_group.name} (#{autoscaling_group.launch_configuration_name})")
|
428
|
+
end
|
429
|
+
}
|
430
|
+
|
376
431
|
task(:update_policy, :roles => :app, :except => { :no_release => true }) {
|
377
432
|
if autoscaling_create_policy
|
378
433
|
if autoscaling_expand_policy and autoscaling_expand_policy.exists?
|
@@ -403,6 +458,20 @@ module Capistrano
|
|
403
458
|
end
|
404
459
|
}
|
405
460
|
|
461
|
+
task(:destroy_policy, :roles => :app, :except => { :no_release => true }) {
|
462
|
+
if autoscaling_expand_policy and autoscaling_expand_policy.exists?
|
463
|
+
logger.debug("Deleting ScalingPolicy for expansion: #{autoscaling_expand_policy.name}")
|
464
|
+
autoscaling_expand_policy.delete()
|
465
|
+
logger.debug("Deleted ScalingPolicy for expansion: #{autoscaling_expand_policy.name}")
|
466
|
+
end
|
467
|
+
|
468
|
+
if autoscaling_shrink_policy and autoscaling_shrink_policy.exists?
|
469
|
+
logger.debug("Deleting ScalingPolicy for shrinking: #{autoscaling_shrink_policy.name}")
|
470
|
+
autoscaling_shrink_policy.delete()
|
471
|
+
logger.debug("Deleted ScalingPolicy for shrinking: #{autoscaling_shrink_policy.name}")
|
472
|
+
end
|
473
|
+
}
|
474
|
+
|
406
475
|
def autoscaling_default_alarm_dimensions(namespace)
|
407
476
|
case namespace
|
408
477
|
when %r{AWS/EC2}i
|
@@ -452,6 +521,26 @@ module Capistrano
|
|
452
521
|
end
|
453
522
|
}
|
454
523
|
|
524
|
+
task(:destroy_alarm, :roles => :app, :except => { :no_release => true }) {
|
525
|
+
autoscaling_expand_alarm_definitions.each do |alarm_name, alarm_options|
|
526
|
+
alarm = autoscaling_cloudwatch_client.alarms[alarm_name]
|
527
|
+
if alarm and alarm.exists?
|
528
|
+
logger.debug("Deleting Alarm for expansion: #{alarm.name}")
|
529
|
+
alarm.delete()
|
530
|
+
logger.debug("Deleted Alarm for expansion: #{alarm.name}")
|
531
|
+
end
|
532
|
+
end
|
533
|
+
|
534
|
+
autoscaling_shrink_alarm_definitions.each do |alarm_name, alarm_options|
|
535
|
+
alarm = autoscaling_cloudwatch_client.alarms[alarm_name]
|
536
|
+
if alarm and alarm.exists?
|
537
|
+
logger.debug("Deleting Alarm for shrinking: #{alarm.name}")
|
538
|
+
alarm.delete()
|
539
|
+
logger.debug("Deleted Alarm for shrinking: #{alarm.name}")
|
540
|
+
end
|
541
|
+
end
|
542
|
+
}
|
543
|
+
|
455
544
|
desc("Suspend AutoScaling processes.")
|
456
545
|
task(:suspend, :roles => :app, :except => { :no_release => true }) {
|
457
546
|
if autoscaling_group and autoscaling_group.exists?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-autoscaling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
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-12-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|