Created
September 18, 2019 08:57
-
-
Save mbaldessari/12830257fefa42ad198cc52aaacfc039 to your computer and use it in GitHub Desktop.
Disables other controller haproxy backends on osp ctlplane
This file contains hidden or 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
#!/bin/bash | |
set -e | |
# Before running this script it would be best to disable haproxy on the other nodes | |
# via: for i in controller-1 controller-2; do pcs resource ban haproxy-bundle $i; done | |
# To clear the bans: for i in controller-1 controller-2; do pcs resource clear haproxy-bundle $i; done | |
# Run this script as root on the single controller you want to stay active | |
CONF="/var/lib/config-data/puppet-generated/haproxy/etc/haproxy/haproxy.cfg" | |
HOST=$(hostname) | |
# Enable admin access to the haproxy stat socket | |
sed -i '/stats.*socket.*user$/s/user/admin/' $CONF | |
pcs resource restart --wait=30 haproxy-bundle | |
function get_servers() { | |
local stanza | |
stanza=$1 | |
text=$(sed -n "/^listen $stanza/,/^$/p" $CONF| grep -e "^\s\+server" | awk '{ print $2}') | |
echo $text | |
} | |
# For each stanza put the other nodes in maintenance mode | |
STANZAS=$(grep -e '^listen\s\+\(\S\+\)$' $CONF | awk '{print $2}') | |
for SERVICE in $STANZAS; do | |
output=$(get_servers $SERVICE) | |
for i in $output; do | |
if [[ "$i" =~ "$HOST" ]]; then | |
echo -n "" | |
else | |
echo "Disabling $SERVICE/$i" | |
echo "disable server $SERVICE/$i" | nc -U /var/lib/haproxy/stats | |
fi | |
done | |
done | |
echo "Verifying state of backends in maintenance mode" | |
echo "show info;show stat" | nc -U /var/lib/haproxy/stats |grep MAINT | |
echo "In order to reenable all backends just run 'pcs resource restart haproxy-bundle'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment