This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
caddy-lb-policy-list: init at v1.0.0
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 |