Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Commit

Permalink
moved the failover functionality to failover-haproxy.py, since it is …
Browse files Browse the repository at this point in the history
…far from complete and contains completely different functionality
  • Loading branch information
erikbergsma committed Jun 4, 2014
1 parent b334649 commit 9775413
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions failover-haproxy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import argparse
import logging
from haproxy_autoscale import steal_elastic_ip
import urllib2

def main():
# Parse up the command line arguments.
parser = argparse.ArgumentParser(description='Update haproxy to use all instances running in a security group.')
parser.add_argument('--access-key', required=True)
parser.add_argument('--secret-key', required=True)
parser.add_argument('--eip',
help='The Elastic IP to bind to when VIP seems unhealthy.')
parser.add_argument('--health-check-url',
help='The URL to check. Assigns EIP to self if health check fails.')
args = parser.parse_args()

# Do a health check on the url if specified.
try:
if args.health_check_url and args.eip:
logging.info('Performing health check.')
try:
logging.info('Checking %s' % args.health_check_url)
response = urllib2.urlopen(args.health_check_url)
logging.info('Response: %s' % response.read())

except:
# Assign the EIP to self.
logging.warn('Health check failed. Assigning %s to self.' % args.eip)
steal_elastic_ip(access_key=args.access_key,
secret_key=args.secret_key,
ip=args.eip )

except:
pass

if __name__ == '__main__':
logging.getLogger().setLevel(logging.INFO)
main()

0 comments on commit 9775413

Please sign in to comment.