add script to en/disable servers from loadbalancers

This commit is contained in:
Jakobus Schürz 2022-06-15 15:18:22 +02:00
parent 0a5e7114db
commit 0a40f58689

59
bin/haproxy-maintenance Executable file
View file

@ -0,0 +1,59 @@
#!/bin/bash
function help() {
cat << EOF
Usage: $(basename $0) <action> <node>
<action> [enable|disable|help]
<node> Nomenklatur ist <svc><cluster><env><node>
<svc> [jra|cnf] 3 characters
<cluster> [0-9] 1 character
<env> [pte] 1 character
<node> [0-9] 1 character
EOF
}
case $1 in
enable)
ACTION=enable
;;
disable)
ACTION=disable
;;
help)
help
exit 0
;;
*)
help
exit 1
;;
esac
shift
UMG=${1:4:1}
CLUSTER=${1:0:4}
NODE=${1:5:1}
LBS=( atlb${UMG}1 atlb${UMG}2 )
BACKENDS=( ${CLUSTER} ${CLUSTER}_direct )
SERVERS=( ${CLUSTER}${NODE} ${CLUSTER}${NODE}d )
HAADMINSOCK=/run/haproxy/admin.sock
i=0
while [ $i -lt ${#BACKENDS[@]} ];do
cat << EOF
Action: $ACTION
Umgebung: $UMG
Cluster: $CLUSTER
Node: $NODE
Loadbalancers: ${LBS[*]}
Backend: ${BACKENDS[$i]}
Server: ${SERVERS[$i]}
------------------------------------
EOF
parallel-ssh -i $(for l in ${LBS[@]};do echo -H $l;done) "echo '$ACTION server ${BACKENDS[$i]}/${SERVERS[$i]}'|socat stdio $HAADMINSOCK"
i=$((i+1))
done