--- a/bin/update Wed Mar 21 18:43:56 2012 +0200
+++ b/bin/update Wed Mar 21 18:59:43 2012 +0200
@@ -38,6 +38,7 @@
# global DHCP conf to test
DHCPD=/usr/sbin/dhcpd
DHCPD_CONF=/etc/dhcp/dhcpd.conf
+DHCPD_INIT=/etc/init.d/isc-dhcp-server
# hg repo to commit
REPO=$DATA
@@ -48,6 +49,7 @@
# XXX: hosts data input charset?
PROCESS_ARGS='--input-charset latin-1'
+DHCP_FILE_ARGS='--input-charset latin-1'
# External bins
NAMED_CHECKZONE=/usr/sbin/named-checkzone
@@ -76,6 +78,9 @@
# Operations; the functions called from run()
source $LIB/update.operations
+## Flags
+# set by do_reload_zone if zone data has actually been reloaded
+RELOAD_ZONES=
## Site settings, used as arguments to scripts
# MX record to generate in hosts --forward-zone
@@ -202,11 +207,25 @@
check_dhcp
}
+# Runs DHCP checks, once DNS hosts have been updated
+function run_dhcp_check {
+ log "Testing dhcp hosts..."
+ for conf in "${DHCP_CONFS[@]}"; do
+ check_dhcp_hosts $DHCP/$conf.conf
+ done
+}
+
function run_deploy {
## Reload zones
log "Reload zones..."
reload_zones
+ ## DHCP
+ run_dhcp_check
+
+ log "Reload dhcp..."
+ reload_dhcp
+
## Commit
log "Commit data..."
commit_data
--- a/lib/update.args Wed Mar 21 18:43:56 2012 +0200
+++ b/lib/update.args Wed Mar 21 18:59:43 2012 +0200
@@ -63,8 +63,8 @@
-m MSG commit message
Deploy:
- -R do not reload zones
- -r force reload zones
+ -R do not reload zones/dhcp
+ -r force reload zones/dhcp
END
}
--- a/lib/update.operations Wed Mar 21 18:43:56 2012 +0200
+++ b/lib/update.operations Wed Mar 21 18:59:43 2012 +0200
@@ -31,6 +31,26 @@
fi
}
+## Run check-command on given file, outputting results:
+#
+# check_generic $src $cmd $args...
+#
+function check_generic {
+ local src=$1; shift
+ local cmd=$1; shift
+
+ if cmd_test $cmd -q "$@"; then
+ log_skip "Check $src: OK"
+
+ else
+ log_error " Check $src: Failed"
+
+ indent " " $cmd "$@"
+
+ exit 1
+ fi
+}
+
## Hosts
## Update hosts from verbatim from input zone data:
#
@@ -274,18 +294,8 @@
function check_dhcp {
local conf=${1:-$DHCPD_CONF}
- local cmd=($DHCPD -cf $conf -t)
-
- if "${cmd[@]}" -q; then
- log_skip "Check $conf: OK"
-
- else
- log_error " Check $conf: Failed"
-
- indent " " "${cmd[@]}"
-
- exit 1
- fi
+ check_generic $conf \
+ $DHCPD -cf $conf -t
}
## Test DHCP configuration of given settings/dhcp using check_dhcp $DHCP_DATA/$host.conf:
@@ -293,16 +303,38 @@
# check_dhcp_conf $conf
#
function check_dhcp_conf {
- local conf=$1
+ local conf=$1;
check_dhcp $DHCP_DATA/$conf.conf
}
+## Test DHCP hosts source configuration for invalid fixed-address stanzas:
+#
+# check_dhcp_hosts $hosts_conf
+#
+function check_dhcp_hosts {
+ local hosts=$1
+
+ # XXX: still too unclear
+ local src=$hosts #$DHCP_DATA/$hosts.conf
+
+ # set in do_reload_zones below
+ if [ $RELOAD_ZONES ]; then
+ check_generic $src \
+ $BIN/check-dhcp-hosts $DHCP_FILE_ARGS $ROOT/$src
+ else
+ log_noop "Check $src: skipped; did not reload DNS zones"
+ fi
+}
+
# Run rndc reload
-function do_reload {
+function do_reload_zones {
# run
indent " rndc: " \
$RNDC reload
+
+ # set flag
+ RELOAD_ZONES=y
}
## Load update zonefiles into bind:
@@ -316,7 +348,7 @@
if [ $RELOAD_FORCE ]; then
log_force "$msg..."
- do_reload
+ do_reload_zones
elif [ $RELOAD_NOOP ]; then
log_noop "$msg: skipped"
@@ -330,7 +362,44 @@
log_update "$msg..."
# run
- do_reload
+ do_reload_zones
+ fi
+}
+
+## Reload DHCP by restarting it, if running:
+#
+# do_reload_dhcp
+#
+# Does NOT restart dhcp if it is not running (status).
+function do_reload_dhcp {
+ if cmd_test $DHCPD_INIT status >/dev/null; then
+ cmd $DHCPD_INIT restart
+ else
+ log_warn "dhcpd not running; did not restart"
+ fi
+}
+
+## Reload dhcp hosts
+#
+# reload_dhcp
+#
+# noop's if we haven't reloaded zones
+function reload_dhcp {
+ local msg="Reload DHCP hosts"
+
+ if [ $RELOAD_FORCE ]; then
+ log_force "$msg..."
+
+ do_reload_dhcp
+
+ elif [ $RELOAD_NOOP ]; then
+ log_noop "$msg: skipped"
+
+ else
+ log_update "$msg..."
+
+ # run
+ do_reload_dhcp
fi
}
--- a/lib/update.utils Wed Mar 21 18:43:56 2012 +0200
+++ b/lib/update.utils Wed Mar 21 18:59:43 2012 +0200
@@ -16,6 +16,17 @@
"$@" || die "Failed"
}
+### Command execution
+## Execute command as a test, logging its execution at log_cmd
+#
+# cmd_test $cmd... && ... || ...
+#
+# Fails if the command returns an error exit code.
+function cmd_test {
+ log_cmd "$@"
+
+ "$@"
+}
## Execute command, prefixing its output on stdout with given indent prefix.
#
# indent " " $cmd...