myshellconfig/bin/haproxy-maintenance
Jakobus Schürz 0831f7ed4f cleanup
2022-08-02 20:02:11 +02:00

129 lines
3.8 KiB
Bash
Executable file

#!/bin/bash
set -euo pipefail
function help() {
cat << EOF
Legt einzelne Nodes aus einem Cluster im Loadbalancer still
Das Skript $(basename $0) wird von der lokalen Workstation aus ausgeführt
Usage: $(basename $0) <action> <node>
$(basename $0) help
<action> enable|disable|serverstate|showstat
<node> Nomenklatur ist <svc><cluster><env><node> (z.B. jra4t1 - Jira, Cluster 4 (ITSM), Test, Node 1)
<svc> [jra|cnf] 3 characters
<cluster> [0-9] 1 character
<env> [pte] 1 character
<node> [0-9] 1 character
<action> showmaint
<node> Nomenklatur ist <svc><cluster><env> (z.B. jra4t - Jira, Cluster 4 (ITSM), Test)
<svc> [jra|cnf] 3 characters
<cluster> [0-9] 1 character
<env> [pte] 1 character
help zeigt diese Hilfe
EOF
}
COMMAND=$1
case ${COMMAND} in
enable)
ACTION=enable
;;
disable)
ACTION=disable
;;
backend)
ACTION=show
WHAT="backend"
;;
serverstate)
ACTION=show
WHAT="servers state"
;;
showstat)
ACTION=show
WHAT="stat"
;;
showmaint)
ACTION=showmaint
WHAT="stat"
;;
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 )
LBS=( sl${UMG}ebsatlassianlb01 sl${UMG}ebsatlassianlb02 )
BACKENDS=( ${CLUSTER} ${CLUSTER}_direct )
SERVERS=( ${CLUSTER}${NODE} ${CLUSTER}${NODE}d )
HAADMINSOCK=/run/haproxy/admin.sock
i=0
case $COMMAND in
backend|showstat)
cat << EOF
Action: $ACTION
Umgebung: $UMG
Cluster: $CLUSTER
Loadbalancers: ${LBS[*]}
Backend: ${BACKENDS[$i]}
What: ${WHAT:-not set}
------------------------------------
EOF
echo "echo '$ACTION $WHAT'|socat stdio $HAADMINSOCK"
parallel-ssh -i $(for l in ${LBS[@]};do echo -H $l;done) "echo '$ACTION $WHAT'|socat stdio $HAADMINSOCK"
;;
*)
while [ $i -lt ${#BACKENDS[@]} ];do
cat << EOF
Action: $ACTION
Umgebung: $UMG
Cluster: $CLUSTER
Node: $NODE
Loadbalancers: ${LBS[*]}
Backend: ${BACKENDS[$i]}
Server: ${SERVERS[$i]}
What: ${WHAT:-not set}
------------------------------------
EOF
case $ACTION in
enable|disable)
echo "echo '$ACTION server ${BACKENDS[$i]}/${SERVERS[$i]}'|socat stdio $HAADMINSOCK"
parallel-ssh --inline-stdout $(for l in ${LBS[@]};do echo -H $l;done) "echo '$ACTION server ${BACKENDS[$i]}/${SERVERS[$i]}'|socat stdio $HAADMINSOCK"
;;
show)
echo "echo '$ACTION $WHAT ${BACKENDS[$i]}'|socat stdio $HAADMINSOCK"
parallel-ssh --inline-stdout $(for l in ${LBS[@]};do echo -H $l;done) "echo '$ACTION $WHAT ${BACKENDS[$i]}'|socat stdio $HAADMINSOCK"
;;
showmaint)
# UMG=t LBS=( sl${UMG}ebsatlassianlb01 sl${UMG}ebsatlassianlb02 )
# UMG=p LBS=( ${LBS[@]} sl${UMG}ebsatlassianlb01 sl${UMG}ebsatlassianlb02 )
echo UMG: ${UMG}
echo LBS: ${LBS[@]}
echo "echo '$ACTION $WHAT ${BACKENDS[$i]}'|socat stdio $HAADMINSOCK"
parallel-ssh --inline-stdout $(for l in ${LBS[@]};do echo -H $l;done) "echo 'show $WHAT ${BACKENDS[$i]}'|socat stdio $HAADMINSOCK"| awk -F, '$1~/^\[[0-9][0-9]*/ {print $0} $18=="MAINT" {print "backend "$1" - "$2" "$18}'
;;
esac
i=$((i+1))
done
;;
esac