myshellconfig/bin/haproxy-maintenance

130 lines
3.8 KiB
Text
Raw Normal View History

#!/bin/bash
2022-08-02 20:02:11 +02:00
set -euo pipefail
function help() {
cat << EOF
2022-07-08 20:49:13 +02:00
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>
2022-07-08 20:49:13 +02:00
$(basename $0) help
2022-08-02 20:02:11 +02:00
<action> enable|disable|serverstate|showstat
2022-07-08 20:49:13 +02:00
<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
2022-08-02 20:02:11 +02:00
<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
2022-07-08 20:49:13 +02:00
help zeigt diese Hilfe
EOF
}
2022-07-08 20:49:13 +02:00
COMMAND=$1
case ${COMMAND} in
enable)
ACTION=enable
;;
disable)
ACTION=disable
;;
2022-07-08 20:49:13 +02:00
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}
2022-07-08 20:49:13 +02:00
#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
2022-07-08 20:49:13 +02:00
case $COMMAND in
backend|showstat)
cat << EOF
Action: $ACTION
Umgebung: $UMG
Cluster: $CLUSTER
Loadbalancers: ${LBS[*]}
Backend: ${BACKENDS[$i]}
2022-08-02 20:02:11 +02:00
What: ${WHAT:-not set}
2022-07-08 20:49:13 +02:00
------------------------------------
2022-07-08 20:49:13 +02:00
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[*]}
2022-07-08 20:49:13 +02:00
Backend: ${BACKENDS[$i]}
Server: ${SERVERS[$i]}
2022-08-02 20:02:11 +02:00
What: ${WHAT:-not set}
------------------------------------
EOF
2022-07-08 20:49:13 +02:00
case $ACTION in
enable|disable)
echo "echo '$ACTION server ${BACKENDS[$i]}/${SERVERS[$i]}'|socat stdio $HAADMINSOCK"
2022-08-02 20:02:11 +02:00
parallel-ssh --inline-stdout $(for l in ${LBS[@]};do echo -H $l;done) "echo '$ACTION server ${BACKENDS[$i]}/${SERVERS[$i]}'|socat stdio $HAADMINSOCK"
2022-07-08 20:49:13 +02:00
;;
show)
echo "echo '$ACTION $WHAT ${BACKENDS[$i]}'|socat stdio $HAADMINSOCK"
2022-08-02 20:02:11 +02:00
parallel-ssh --inline-stdout $(for l in ${LBS[@]};do echo -H $l;done) "echo '$ACTION $WHAT ${BACKENDS[$i]}'|socat stdio $HAADMINSOCK"
2022-07-08 20:49:13 +02:00
;;
showmaint)
2022-08-02 20:02:11 +02:00
# UMG=t LBS=( sl${UMG}ebsatlassianlb01 sl${UMG}ebsatlassianlb02 )
# UMG=p LBS=( ${LBS[@]} sl${UMG}ebsatlassianlb01 sl${UMG}ebsatlassianlb02 )
echo UMG: ${UMG}
2022-07-08 20:49:13 +02:00
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