packages: dhcp/dhcp.init - improved checkconfig output - check for interfac...
glen
glen at pld-linux.org
Mon Jun 29 02:16:14 CEST 2009
Author: glen Date: Mon Jun 29 00:16:14 2009 GMT
Module: packages Tag: HEAD
---- Log message:
- improved checkconfig output
- check for interfaces state in checkconfig (dhcpd refuses to startup if no addresses present and dumps loud message on screen)
---- Files affected:
packages/dhcp:
dhcp.init (1.21 -> 1.22)
---- Diffs:
================================================================
Index: packages/dhcp/dhcp.init
diff -u packages/dhcp/dhcp.init:1.21 packages/dhcp/dhcp.init:1.22
--- packages/dhcp/dhcp.init:1.21 Wed Dec 3 02:11:08 2008
+++ packages/dhcp/dhcp.init Mon Jun 29 02:16:09 2009
@@ -23,42 +23,85 @@
exit 0
fi
-checkconfig() {
- show "Checking %s configuration" "DHCP Server"
+check_device_up()
+{
+ local DEVICE=$1
+ if LC_ALL=C ip addr show dev $DEVICE | grep -q inet; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+# configtest itself
+configtest() {
+ local rc out
out=`/sbin/dhcpd -t 2>&1`; rc=$?
if [ $rc -gt 0 ]; then
- fail
echo >&2 "$out"
- else
- ok
fi
+
+ # check if interfaces specified exist and have addresses
+ for i in $DHCPD_INTERFACES; do
+ if ! check_device_up $i; then
+ echo >&2 "Device '$i' does not exist or has no address configured"
+ rc=1
+ fi
+ done
+
return $rc
}
-start() {
- # Check if the service is already running?
- if [ ! -f /var/lock/subsys/dhcpd ]; then
- msg_starting "DHCP Server"
- daemon /sbin/dhcpd $DHCPD_INTERFACES
+# wrapper for configtest:
+checkconfig() {
+ local details=${1:-0}
+
+ if [ $details = 1 ]; then
+ # run config test and display report (status action)
+ show "Checking %s configuration" "DHCP Server"; busy; echo
+ configtest
RETVAL=$?
- [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd
else
+ # run config test and abort with nice message if failed
+ # (for actions checking status before action).
+ configtest >/dev/null 2>&1
+ RETVAL=$?
+ if [ $RETVAL != 0 ]; then
+ show "Checking %s configuration" "DHCP Server"; fail
+ echo >&2 "Configuration test failed. Run \"$0 checkconfig\" to see errors."
+ exit $RETVAL
+ fi
+ fi
+}
+
+start() {
+ # Check if the service is already running?
+ if [ -f /var/lock/subsys/dhcpd ]; then
msg_already_running "DHCP Server"
+ return
fi
+
+ checkconfig
+ msg_starting "DHCP Server"
+ daemon /sbin/dhcpd $DHCPD_INTERFACES
+ RETVAL=$?
+ [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd
}
stop() {
- if [ -f /var/lock/subsys/dhcpd ]; then
- msg_stopping "DHCP Server"
- killproc dhcpd
- rm -f /var/run/dhcpd.pid /var/lock/subsys/dhcpd >/dev/null 2>&1
- else
+ if [ ! -f /var/lock/subsys/dhcpd ]; then
msg_not_running "DHCP Server"
+ return
fi
+
+ msg_stopping "DHCP Server"
+ killproc dhcpd
+ rm -f /var/run/dhcpd.pid /var/lock/subsys/dhcpd >/dev/null 2>&1
}
condrestart() {
if [ -f /var/lock/subsys/dhcpd ]; then
+ checkconfig
stop
start
else
@@ -71,27 +114,24 @@
# See how we were called.
case "$1" in
start)
- checkconfig || exit 1
start
;;
stop)
stop
;;
restart)
- checkconfig || exit 1
+ checkconfig
stop
start
;;
try-restart)
- checkconfig || exit 1
condrestart 0
;;
force-reload)
- checkconfig || exit 1
condrestart 7
;;
checkconfig)
- checkconfig
+ checkconfig 1
;;
status)
status dhcpd
================================================================
---- CVS-web:
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/packages/dhcp/dhcp.init?r1=1.21&r2=1.22&f=u
More information about the pld-cvs-commit
mailing list