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?
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
section "--------------------"
section "Removing service"
docker-compose down --rmi all --remove-orphans
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
fi
@ -102,6 +110,16 @@ for dir in /docker/* ; do
run docker-compose up -d --remove-orphans
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 [ -f "/docker/$service/nginx_server.conf" ] ; then
section "Copy nginx conf"

View File

@ -1,5 +1,8 @@
#!/bin/bash
# This script echo ipv4 addresses of a symbolic name.
# One IP per line
set -euo pipefail
########################### Helpers ###########################################
@ -19,10 +22,31 @@ function say {
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 ###########################################
verbose=false
if [ "$1" = '-v' ] ; then
if [ "$#" -gt 1 ] && [ "$1" = '-v' ] ; then
verbose=true
shift
fi
@ -34,28 +58,6 @@ if [ "$#" -ne 1 ] ; then
options : -v verbose"
fi
name="$1"
########################### script ############################################
while true ; do
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
resolv "$1"

View File

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