Last active
May 17, 2024 12:11
-
-
Save maxguzenski/0985b051ab402fecd367 to your computer and use it in GitHub Desktop.
Maintenance mode on aws elb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Run with: | |
# aws-elb-maintenance on | |
# or | |
# aws-elb-maintenance off | |
require 'rubygems' | |
require 'aws' | |
ON_MAIN_PORT = 81 # on maintanence (site is NOT running) | |
OFF_MAIN_PORT = 80 # off maintanence (site IS running) | |
ELB_NAME = 'your_elb_name' | |
ELB_CERT = 'arn:aws:iam::226094241980:server-certificate/your_cert_name' | |
if ARGV[0] == 'on' #go on maintanence mode (site is NOT running) | |
elb = AWS::ELB.new.load_balancers[ELB_NAME] | |
elb.listeners.each {|l| l.delete } | |
elb.listeners.create({ | |
port: 443, protocol: :https, instance_port: ON_MAIN_PORT, instance_protocol: :http, | |
server_certificate: ELB_CERT | |
}) | |
elb.listeners.create({ | |
port: 80, protocol: :http, instance_port: ON_MAIN_PORT, instance_protocol: :http | |
}) | |
end | |
if ARGV[0] == 'off' #go off maintanence mode (site is running) | |
elb = AWS::ELB.new.load_balancers[ELB_NAME] | |
elb.listeners.each {|l| l.delete } | |
elb.listeners.create({ | |
port: 443, protocol: :https, instance_port: OFF_MAIN_PORT, instance_protocol: :http, | |
server_certificate: ELB_CERT | |
}) | |
elb.listeners.create({ | |
port: 80, protocol: :http, instance_port: OFF_MAIN_PORT, instance_protocol: :http | |
}) | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http { | |
server { | |
listen 80 default deferred; | |
listen 81 default deferred; | |
if ($server_port = 81) { | |
return 503; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment