Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
caddy-lb-policy-list: init at v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kreatoo committed Jun 24, 2024
1 parent adf6cab commit 814d6b4
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions caddy/caddy-lb-policy-list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
###~ description: List all load balancer policies for all Caddy servers
VERSION="1.0.0"

if [[ "$1" == "--version" ]] || [[ "$1" == "-v" ]]; then
echo "v$VERSION"
exit 0
fi

function warn() {
echo "warning: $1"
}

function init_list() {
printf "%-10s" "|"
printf "%15s" "SERVERS"
printf "%17s" " | "
for i in $@; do
line=$(echo $i | cut -d';' -f2)
printf "%s" " $line | "
done
echo
}

function show_list() {
if [[ ! -d "/tmp/glb/$1" ]]; then
warn "glb directory for $1 doesn't exist, please run caddy-lb-policy-switcher first"
return
fi

printf "%-40s" "| $1"
printf "|"

for lb in /tmp/glb/$1/*; do
if [[ -f "$lb/lb_policy" ]]; then
printf "%s" " $(cat $lb/lb_policy) |"
fi
done
echo
}

for i in /etc/glb/*.conf; do
. "$i"
init_list "${CADDY_API_URLS[@]}"
for server in ${CADDY_SERVERS[@]}; do
show_list "$server"
done
done

0 comments on commit 814d6b4

Please sign in to comment.