Created
April 8, 2026 04:12
-
-
Save wiedehopf/16da39cf84438aa820c8cb490e1fdbb4 to your computer and use it in GitHub Desktop.
haproxy scripts
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 | |
| if [[ -z "$1" ]]; then | |
| echo no arg | |
| exit 1 | |
| fi | |
| IDS=$(echo show sess | socat stdio UNIX-CLIENT:/run/haproxy-admin.sock | grep -F "$1") | |
| echo dropping the following sessions: | |
| echo "$IDS" | |
| IDS=$(echo "$IDS" | cut -f1 -d:) | |
| CMD="" | |
| for ID in $IDS | |
| do | |
| CMD+="shutdown session $ID;" | |
| done | |
| CMD=${CMD::-1} | |
| echo | |
| echo sending command to haproxy: "$CMD" | |
| echo "$CMD" | socat stdio UNIX-CLIENT:/run/haproxy-admin.sock |
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 | |
| hacommand() { echo "$@" | socat stdio UNIX-CLIENT:/run/haproxy-admin.sock; } | |
| acl=/etc/haproxy/$1 | |
| if [[ -n "$2" ]]; then | |
| if grep -qsF -e "$2" "$acl" &>/dev/null; then | |
| echo "already in list: $2" | |
| else | |
| echo "$2" >> "$acl" | |
| fi | |
| fi | |
| WD=/run/updatetable | |
| mkdir -p "$WD" | |
| live="$WD/live" | |
| disk="$WD/disk" | |
| add="$WD/add" | |
| del="$WD/del" | |
| # remove key from live acl, sort, remove duplicates, remove empty lines | |
| hacommand show acl "$acl" | cut -d ' ' -f 2 | sort | uniq | awk 'NF' > "$live" | |
| # sort file on disk, remove comments and empty lines, remove duplicate lines, remove leading spaces | |
| sort < "$acl" | awk '/^[^#]/' | awk 'NF' | sed -e 's/^ *//' | uniq > "$disk" | |
| diff "$live" "$disk" | grep -E '^> ' | sed -e 's/^> *//' > "$add" | |
| diff "$disk" "$live" | grep -E '^> ' | sed -e 's/^> *//' > "$del" | |
| # add entries missing in live | |
| echo Adding ............ | |
| while IFS='' read -r line; do | |
| echo -n "$line" | |
| hacommand add acl "$acl" "$line" | |
| done < "$add" | |
| echo .............. done. | |
| # delete entries missing on disk | |
| echo Deleting .......... | |
| while IFS='' read -r line; do | |
| echo -n "$line" | |
| hacommand del acl "$acl" "$line" | |
| done < "$del" | |
| echo .............. done. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment