class Elb::Deploy

Attributes

instance_id[R]

Public Class Methods

new(options={}) click to toggle source
# 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

Public Instance Methods

add_inbound() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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]) # takes a while for the elb to deregister
end
drop_inbound() click to toggle source
# 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() click to toggle source
# File lib/elb/deploy.rb, line 29
def elb
  return @elb if @elb
  @elb = asg.load_balancers.first
end
register() click to toggle source
# 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() click to toggle source
# File lib/elb/deploy.rb, line 53
def restart
  UI.say("Restarting server")
  system(@options[:restart_command])
end
run() click to toggle source
# 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) click to toggle source
# File lib/elb/deploy.rb, line 72
def wait(n)
  sleep n
end
warm() click to toggle source
# File lib/elb/deploy.rb, line 58
def warm
  UI.say("Warming up server")
  system(@options[:warm_command])
end