Class: Elb::Deploy
- Inherits:
-
Object
show all
- Includes:
- Helper
- Defined in:
- lib/elb/deploy.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helper
#as, #cfn, #ec2, #r53, #rds, #setup_aws
Constructor Details
#initialize(options = {}) ⇒ Deploy
Returns a new instance of Deploy.
6
7
8
9
10
|
# File 'lib/elb/deploy.rb', line 6
def initialize(options={})
@options = options
@instance_id = options[:instance_id] || %x[curl -s http://instance-data.ec2.internal/latest/meta-data/instance-id].strip
setup_aws
end
|
Instance Attribute Details
#instance_id ⇒ Object
Returns the value of attribute instance_id.
5
6
7
|
# File 'lib/elb/deploy.rb', line 5
def instance_id
@instance_id
end
|
Instance Method Details
#add_inbound ⇒ Object
48
49
50
|
# File 'lib/elb/deploy.rb', line 48
def add_inbound
%x{sudo /sbin/iptables -D INPUT -j DROP -p tcp --destination-port 80 -i eth0}
end
|
#asg ⇒ Object
23
24
25
26
27
|
# File 'lib/elb/deploy.rb', line 23
def asg
return @asg if @asg
name = ec2.instances[instance_id].tags["aws:autoscaling:groupName"]
@asg = as.groups[name]
end
|
#deregister ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/elb/deploy.rb', line 34
def deregister
UI.say("Deregistering server from ELB")
return true if @options[:noop]
elb.client.deregister_instances_from_load_balancer(
:load_balancer_name => elb.name,
:instances => [{:instance_id => @instance_id}]
)
wait(@options[:wait]) end
|
#drop_inbound ⇒ Object
44
45
46
|
# File 'lib/elb/deploy.rb', line 44
def drop_inbound
%x{sudo /sbin/iptables -A INPUT -j DROP -p tcp --destination-port 80 -i eth0}
end
|
#elb ⇒ Object
29
30
31
32
|
# File 'lib/elb/deploy.rb', line 29
def elb
return @elb if @elb
@elb = asg.load_balancers.first
end
|
#register ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/elb/deploy.rb', line 63
def register
UI.say("Registering server with ELB")
return true if @options[:noop]
elb.client.register_instances_with_load_balancer(
:load_balancer_name => elb.name,
:instances => [{:instance_id => @instance_id}]
)
end
|
#restart ⇒ Object
53
54
55
56
|
# File 'lib/elb/deploy.rb', line 53
def restart
UI.say("Restarting server")
system(@options[:restart_command])
end
|
#run ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/elb/deploy.rb', line 12
def run
UI.say("Restarting server started")
deregister
drop_inbound
restart
warm
add_inbound
register
UI.say("Restarting server completed")
end
|
#wait(n) ⇒ Object
72
73
74
|
# File 'lib/elb/deploy.rb', line 72
def wait(n)
sleep n
end
|
#warm ⇒ Object
58
59
60
61
|
# File 'lib/elb/deploy.rb', line 58
def warm
UI.say("Warming up server")
system(@options[:warm_command])
end
|