support for multiple ip

This commit is contained in:
Adrian Amaglio 2023-05-02 16:23:37 +02:00
parent b7757e4168
commit da3341bb2e
3 changed files with 47 additions and 26 deletions

View File

@ -78,14 +78,22 @@ for dir in /docker/* ; do
# Is service meant to be on this server? # Is service meant to be on this server?
ip="$(ipof "$service")" ip="$(ipof "$service")"
[ -z "$ip" ] && yell "No IP found for $service" && continue [ -z "$ip" ] && echo "No ip found for $service"
if [ "$ip" != "$my_ip" ] ; then if [[ "$ip" != *"$my_ip"* ]] ; then
if [ -n "$(docker ps | grep "$docker_service")" ] ; then if [ -n "$(docker ps | grep "$docker_service")" ] ; then
section "--------------------" section "--------------------"
section "Removing service" section "Removing service"
docker-compose down --rmi all --remove-orphans docker-compose down --rmi all --remove-orphans
fi fi
# If there is an install script?
if [ -x "/docker/$service/install.sh" ] ; then
section "Running install script"
. "/docker/$service/install.sh"
stop
unset -f start stop reload restart
fi
continue continue
fi fi
@ -102,6 +110,16 @@ for dir in /docker/* ; do
run docker-compose up -d --remove-orphans run docker-compose up -d --remove-orphans
fi fi
# If there is an install script?
if [ -f "/docker/$service/install.sh" ] ; then
section "Running install script"
. "/docker/$service/install.sh"
start
unset -f start stop reload restart
fi
# If there is a nginx conf file # If there is a nginx conf file
if [ -f "/docker/$service/nginx_server.conf" ] ; then if [ -f "/docker/$service/nginx_server.conf" ] ; then
section "Copy nginx conf" section "Copy nginx conf"

View File

@ -1,5 +1,8 @@
#!/bin/bash #!/bin/bash
# This script echo ipv4 addresses of a symbolic name.
# One IP per line
set -euo pipefail set -euo pipefail
########################### Helpers ########################################### ########################### Helpers ###########################################
@ -19,10 +22,31 @@ function say {
fi fi
} }
function resolv () {
if [ "$#" -ne 1 ] ; then
die "usage: $0 <name>"
fi
name="$1"
say "Querying $name"
while read line ; do
if [[ "$line" = *"is an alias for "* ]] ; then
resolv "$(echo "$line" | cut -d ' ' -f 6)"
elif [[ "$line" = *" has address "* ]] ; then
echo "$line" | cut -d ' ' -f 4
elif [[ "$line" = *" not found: "* ]] ; then
continue
elif [[ "$line" = *" has no A record" ]] ; then
continue
else
say "unmatched: $line"
fi
done <<< "$(host -W 2 -t A "$name" localhost)"
}
########################### Options ########################################### ########################### Options ###########################################
verbose=false verbose=false
if [ "$1" = '-v' ] ; then if [ "$#" -gt 1 ] && [ "$1" = '-v' ] ; then
verbose=true verbose=true
shift shift
fi fi
@ -34,28 +58,6 @@ if [ "$#" -ne 1 ] ; then
options : -v verbose" options : -v verbose"
fi fi
name="$1"
########################### script ############################################ ########################### script ############################################
while true ; do resolv "$1"
if "$verbose" ; then
say "Querying $name"
fi
while read line ; do
if [[ "$line" = *"is an alias for "* ]] ; then
name="$(echo "$line" | cut -d ' ' -f 6)"
break
elif [[ "$line" = *" has address "* ]] ; then
echo "$line" | cut -d ' ' -f 4
exit 0
elif [[ "$line" = *" not found: "* ]] ; then
exit 0
elif [[ "$line" = *" has no A record" ]] ; then
exit 0
else
say "unmatched: $line"
fi
done <<< "$(host -W 2 -t A "$name" localhost)"
done

View File

@ -16,6 +16,7 @@ $TTL 604800
@ IN NS ns5.he.net. @ IN NS ns5.he.net.
@ IN A 51.255.33.248 @ IN A 51.255.33.248
@ IN A 82.65.204.254
@ 10800 IN MX 10 spool.mail.gandi.net. @ 10800 IN MX 10 spool.mail.gandi.net.
@ 10800 IN MX 50 fb.mail.gandi.net. @ 10800 IN MX 50 fb.mail.gandi.net.