From da3341bb2ea9f93a8e402d34dba32a9a7dd91d59 Mon Sep 17 00:00:00 2001 From: Adrian Amaglio Date: Tue, 2 May 2023 16:23:37 +0200 Subject: [PATCH] support for multiple ip --- .../roles/deploy_all/files/bin/deployer.sh | 22 +++++++- .../roles/deploy_all/files/bin/resolv.sh | 50 ++++++++++--------- .../deploy_all/files/bind/db.jean-cloud.net | 1 + 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/provisioning/roles/deploy_all/files/bin/deployer.sh b/provisioning/roles/deploy_all/files/bin/deployer.sh index 23ef84e..590efaf 100755 --- a/provisioning/roles/deploy_all/files/bin/deployer.sh +++ b/provisioning/roles/deploy_all/files/bin/deployer.sh @@ -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" diff --git a/provisioning/roles/deploy_all/files/bin/resolv.sh b/provisioning/roles/deploy_all/files/bin/resolv.sh index 562e126..9aa8a01 100755 --- a/provisioning/roles/deploy_all/files/bin/resolv.sh +++ b/provisioning/roles/deploy_all/files/bin/resolv.sh @@ -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 " + 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" diff --git a/provisioning/roles/deploy_all/files/bind/db.jean-cloud.net b/provisioning/roles/deploy_all/files/bind/db.jean-cloud.net index 13032db..36b9038 100644 --- a/provisioning/roles/deploy_all/files/bind/db.jean-cloud.net +++ b/provisioning/roles/deploy_all/files/bind/db.jean-cloud.net @@ -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.