Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- : ${HAPROXY_PATCHED:=/etc/haproxy/haproxy.cfg.auto-scaling}
- : ${HAPROXY_TEMPLATE:=/etc/haproxy/haproxy.cfg.auto-scaling.template}
- : ${MARFEEL_AUTOSCALING_GROUP:=marfeelcandidate4-auto-scaling-group}
- : ${HAPROXY:=/usr/sbin/haproxy}
- yell() { echo -e "$0: $*" >&2; }
- die() { yell "$*"; exit 1; }
- die_and_yell() { yell "$1"; exit $2; }
- try() { "$@" || die "cannot $*"; }
- if (( $# != 1 )); then
- die "Wrong number of arguments: $0 + final haproxy.cfg file\n\n - You can also set some environment variables, like MARFEEL_AUTOSCALING_GROUP, check the man page"
- fi
- HAPROXY_CFG=$1;
- HAPROXY_CFG_DIR=`dirname ${HAPROXY_CFG}`
- if [ -e ${HAPROXY_CFG_DIR} ]; then
- cp ${HAPROXY_TEMPLATE} ${HAPROXY_PATCHED}
- #for i in `aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name marfeelcandidate4-auto-scaling-group | grep INSTANCES | awk '{ print $4}'`; do aws ec2 describe-instances --instance-ids $i | grep ASSOCIATION | awk '{ print $4 }' | head -1; done | xargs -L 1 -I IP sed -i "0,/autoscale_ip/s//IP/" ${HAPROXY_PATCHED}
- for i in `aws autoscaling describe-auto-scaling-groups --auto-scaling-group-name marfeelcandidate4-auto-scaling-group | grep INSTANCES | awk '{ print $4}'`; do aws ec2 describe-instances --instance-ids $i | grep ASSOCIATION | awk '{ print $4 }' | head -1; done | xargs -L 1 -I IP echo " server marfeel-candidate-4-webserver IP:80/ check" >> ${HAPROXY_PATCHED}
- if [[ $? == 0 ]]; then
- ${HAPROXY} -c -f ${HAPROXY_PATCHED} -q
- if [[ $? == 0 ]]; then
- cp ${HAPROXY_PATCHED} ${HAPROXY_CFG}
- /etc/init.d/haproxy restart
- if [[ $? != 0 ]]; then
- die "Panic, check what happened"
- fi
- echo "haproxy restarted"
- # some housekeeping, remove the temporal patched file
- rm ${HAPROXY_PATCHED}
- else
- echo "HOLA"
- die "Wrong ${HAPROXY_PATCHED} syntax, please check it"
- fi
- exit 0
- else
- die "Problem patching the ${HAPROXY_TEMPLATE} file."
- fi
- fi
- die "Something went wrong"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement