From 29dac338962db92a4877846ddc2ccb89d0886994 Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Thu, 21 Feb 2013 09:54:35 +0000 Subject: [PATCH] Changement de "ou" le dns se fait reloader/reconfigurer. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plus propre et mieux scindé. Quand le DNS ou l'apache se fait reloader/reconfigurer, appel en "hooks" des scripts qui sont dans /usr/lib/alternc/reload.d/ --- debian/alternc.dirs | 1 + src/alternc_reload | 3 --- src/functions_dns.sh | 21 ++++++++++++++++----- src/update_domains.sh | 33 ++++++++++++--------------------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/debian/alternc.dirs b/debian/alternc.dirs index 51b012ef..7edbc424 100644 --- a/debian/alternc.dirs +++ b/debian/alternc.dirs @@ -14,6 +14,7 @@ usr/bin usr/share/alternc/panel usr/lib/alternc usr/lib/alternc/install.d +usr/lib/alternc/reload.d usr/lib/alternc/safe_mode_exec_dir usr/sbin usr/share/alternc/install diff --git a/src/alternc_reload b/src/alternc_reload index d529ad1b..005b6964 100755 --- a/src/alternc_reload +++ b/src/alternc_reload @@ -69,9 +69,6 @@ if [ ! -z "$RELOAD_ZONES" ]; then $sudo rndc reload || echo "Cannot reload bind" apache_reload # keep for compatibility ;; - "dns_daemon") - dns_restart - ;; "apache") apache_reload ;; diff --git a/src/functions_dns.sh b/src/functions_dns.sh index 3cf21019..538e85fa 100755 --- a/src/functions_dns.sh +++ b/src/functions_dns.sh @@ -9,6 +9,7 @@ ZONE_TEMPLATE="/etc/alternc/templates/bind/templates/zone.template" NAMED_TEMPLATE="/etc/alternc/templates/bind/templates/named.template" NAMED_CONF="/var/lib/alternc/bind/automatic.conf" +RNDC="/usr/sbin/rndc" dns_zone_file() { echo "/var/lib/alternc/bind/zones/$1" @@ -56,18 +57,21 @@ dns_named_conf() { tempo=${tempo/@@DOMAINE@@/$domain} tempo=${tempo/@@ZONE_FILE@@/$(dns_zone_file $domain)} echo $tempo >> "$NAMED_CONF" + # Kindly ask Bind to reload his configuration + # (the zone file is allready created and populate) + $RNDC reconfig + # Hook it ! + run-parts --arg=dns_reconfig /usr/lib/alternc/reload.d fi - # Ask for restart of dns server - touch "$DNS_DO_RESTART" } dns_delete() { local domain=$1 # Delete the zone file - if [ -w $(dns_zone_file $domain) ] ; then - rm -f $(dns_zone_file $domain) + if [ -w "$(dns_zone_file $domain)" ] ; then + rm -f "$(dns_zone_file $domain)" fi # Remove from the named conf @@ -75,7 +79,9 @@ dns_delete() { echo -e "$file" |grep -v "\"$domain\"" > "$NAMED_CONF" # Ask for restart of dns server - touch "$DNS_DO_RESTART" + $RNDC reconfig + # Hook it ! + run-parts --arg=dns_reconfig /usr/lib/alternc/reload.d } # DNS regenerate @@ -142,4 +148,9 @@ dns_regenerate() { dns_chmod $domain # Add it to named conf dns_named_conf $domain + + # Kindly bind to reload the zone + $RNDC reload $domain + # Hook it ! + run-parts --arg=dns_reload_zone --arg="$domain" /usr/lib/alternc/reload.d } diff --git a/src/update_domains.sh b/src/update_domains.sh index 2e3ff1ac..8d3bdc42 100644 --- a/src/update_domains.sh +++ b/src/update_domains.sh @@ -20,12 +20,9 @@ LOCK_FILE="/usr/share/alternc/panel/cron.lock" # FIXME doesn't seem clean to be OLDIFS="$IFS" NEWIFS=" " LOGFORMAT_FILE="/etc/alternc/apache_logformat.conf" -RELOAD_ZONES="$(mktemp /tmp/alternc_reload_zones.XXXX)" RELOAD_WEB="$(mktemp /tmp/alternc_reload_web.XXXX)" -DNS_DO_RESTART="/tmp/alternc.do_do_restart.$$" B="µµ§§" # Strange letters to make split in query -echo "" > "$RELOAD_ZONES" echo "" > "$RELOAD_WEB" # Somes check before start operations @@ -95,7 +92,6 @@ for dom in `mysql_query "select domaine from domaines where dns_action = 'UPDATE do dns_delete $dom mysql_query "update domaines set dns_action = 'OK', dns_result = '$?' where domaine = '$dom'" - echo -n " $dom " >> "$RELOAD_ZONES" done # Domains we have to update the dns : @@ -105,7 +101,6 @@ do echo "dns_regenerate : domain=/$dom/" dns_regenerate $dom mysql_query "update domaines set dns_action = 'OK', dns_result = '$?' where domaine = '$dom'" - echo -n " $dom " >> "$RELOAD_ZONES" done # Domains we want to delete completely, now we do it @@ -115,11 +110,9 @@ do dns_delete $dom # Web configurations have already bean cleaned previously mysql_query "delete from sub_domaines where domaine='$dom'; delete from domaines where domaine='$dom';" - echo -n " $dom " >> "$RELOAD_ZONES" done if [ ! -z "$(cat "$RELOAD_WEB")" ] ; then - echo " apache " >> "$RELOAD_ZONES" # Just to encourage user to use THIS directory and not another one test -d "$VHOST_MANUALCONF" || mkdir -p "$VHOST_MANUALCONF" @@ -150,23 +143,21 @@ if [ ! -z "$(cat "$RELOAD_WEB")" ] ; then fi mv "$tempo" "$VHOST_FILE" + # We must reload apache + # we assume we run apache on the master + /usr/bin/alternc_reload apache || true + # Launch hooks for apache reload + run-parts --arg=web_reload /usr/lib/alternc/reload.d fi -# What do we reload ? -lst_zones=$(cat "$RELOAD_ZONES"|tr '\n' ' ') -if [ -e "$DNS_DO_RESTART" ] ; then - lst_zones="dns_daemon $lst_zones" -fi +## FIXME : move the slave part into the /usr/lib/alternc/reload.d directory to be an hook +#for slave in $ALTERNC_SLAVES; do +# if [ "$slave" != "localhost" ]; then +# ssh alternc@$slave alternc_reload 'apache' || true +# fi +#done -# we assume we run apache and bind on the master -/usr/bin/alternc_reload $lst_zones || true -for slave in $ALTERNC_SLAVES; do - if [ "$slave" != "localhost" ]; then - ssh alternc@$slave alternc_reload $lst_zones || true - fi -done - -rm -f "$LOCK_FILE" "$RELOAD_ZONES" "$RELOAD_WEB" "$DNS_DO_RESTART" "$INOTIFY_UPDATE_DOMAIN" +rm -f "$LOCK_FILE" "$RELOAD_ZONES" "$RELOAD_WEB" "$INOTIFY_UPDATE_DOMAIN" exit 0