Date: Wed, 25 Mar 2009 22:58:06 +0300 (MSK) From: Eygene Ryabinkin <rea-fbsd@codelabs.ru> To: FreeBSD-gnats-submit@FreeBSD.org Subject: ports/133072: [patch] net/isc-dhcp30-server, net/isc-dhcp30-server: check configuration file before restart Message-ID: <20090325195806.071DA17123@amnesiac.at.no.dns> Resent-Message-ID: <200903252000.n2PK03n3035263@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 133072 >Category: ports >Synopsis: [patch] net/isc-dhcp30-server, net/isc-dhcp30-server: check configuration file before restart >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Mar 25 20:00:02 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Eygene Ryabinkin >Release: FreeBSD 7.2-PRERELEASE amd64 >Organization: Code Labs >Environment: System: FreeBSD 7.2-PRERELEASE amd64 >Description: Had just been beaten by the following (silly) error: I had made a mistake in the DHCP configuration file, restarted daemon and started to scratch my head in order to understarnd why clients aren't getting their IPs and other stuff. I understarnd that it is my fault, but if rc.d script will be able to test configuration and refuse to start with the broken config file -- it will be great. Moreover, there is no point in doing restart with the broken configuration file -- it is better to leave the running instance. >How-To-Repeat: Make a mistake in the configuration file and do '/usr/local/etc/rc.d/isc-dhcpd restart'. You'll see the following output: ----- Stopping dhcpd. Starting dhcpd. ----- Sounds like everything is good, but in reality dhcpd daemon will not be running. >Fix: The following patch adds the check both to the rc.d script for DHCPD 3.0 and 3.1. I had tested it for 3.0, but it should also work for 3.1. --- implement-configuration-file-check.diff begins here --- >From 5d719245842864e73515d976b8a32f20a9437db3 Mon Sep 17 00:00:00 2001 From: Eygene Ryabinkin <rea-fbsd@codelabs.ru> Date: Wed, 25 Mar 2009 22:29:31 +0300 This feature is very handy, because when 'restart' cmd is run with the broken configuration file, rc.d script will show that it stops and starts the daemon. And one will discover that dhcp daemon isn't running only on the next restart or looking at the process list -- not cool. Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru> --- net/isc-dhcp30-server/files/isc-dhcpd.in | 20 ++++++++++++++++++++ net/isc-dhcp31-server/files/isc-dhcpd.in | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+), 0 deletions(-) diff --git a/net/isc-dhcp30-server/files/isc-dhcpd.in b/net/isc-dhcp30-server/files/isc-dhcpd.in index 9532d91..0bc65bb 100644 --- a/net/isc-dhcp30-server/files/isc-dhcpd.in +++ b/net/isc-dhcp30-server/files/isc-dhcpd.in @@ -701,6 +701,25 @@ dhcpd_uninstall () fi } +dhcpd_checkconfig () +{ + local rc_flags_saved rc_flags_our + rc_flags_saved="$rc_flags" + setup_flags + # Eliminate '-q' flag if it is present + rc_flags_our=`echo "${rc_flags}" | sed -Ee's/(^-q | -q | -q$)'//` + rc_flags="${rc_flags_saved}" + if ${command} -t -q ${rc_flags_our}; then + true + else + echo "Configuration file sanity check failed:" + echo "=======================================" + ${command} -t ${rc_flags_our} + echo "=======================================" + false + fi +} + rcvar=${name}_enable load_rc_config ${name} @@ -719,6 +738,7 @@ pidfile=${_dhcpd_pidfile} required_files=${dhcpd_conf} start_precmd=${name}_precmd stop_postcmd=${name}_postcmd +restart_precmd="dhcpd_checkconfig" install_cmd=dhcpd_install uninstall_cmd=dhcpd_uninstall extra_commands="install uninstall" diff --git a/net/isc-dhcp31-server/files/isc-dhcpd.in b/net/isc-dhcp31-server/files/isc-dhcpd.in index 6ed05f8..b526bfb 100644 --- a/net/isc-dhcp31-server/files/isc-dhcpd.in +++ b/net/isc-dhcp31-server/files/isc-dhcpd.in @@ -700,6 +700,25 @@ dhcpd_uninstall () fi } +dhcpd_checkconfig () +{ + local rc_flags_saved rc_flags_our + rc_flags_saved="$rc_flags" + setup_flags + # Eliminate '-q' flag if it is present + rc_flags_our=`echo "${rc_flags}" | sed -Ee's/(^-q | -q | -q$)'//` + rc_flags="${rc_flags_saved}" + if ${command} -t -q ${rc_flags_our}; then + true + else + echo "Configuration file sanity check failed:" + echo "=======================================" + ${command} -t ${rc_flags_our} + echo "=======================================" + false + fi +} + rcvar=${name}_enable load_rc_config ${name} @@ -718,6 +737,7 @@ pidfile=${_dhcpd_pidfile} required_files=${dhcpd_conf} start_precmd=${name}_precmd stop_postcmd=${name}_postcmd +restart_precmd="dhcpd_checkconfig" install_cmd=dhcpd_install uninstall_cmd=dhcpd_uninstall extra_commands="install uninstall" -- 1.6.1.3 --- implement-configuration-file-check.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090325195806.071DA17123>