]> git.pld-linux.org Git - packages/dhcp.git/commitdiff
- sync with dhcp.init
authorElan Ruusamäe <glen@pld-linux.org>
Thu, 19 Nov 2009 20:25:10 +0000 (20:25 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    dhcp6.init -> 1.4

dhcp6.init

index 358f49b23821c5774166ac19685af6eb528476b8..e0e8f0a4707fb63312c2781bceed9600566a956a 100644 (file)
@@ -23,78 +23,123 @@ else
        exit 0
 fi
 
-checkconfig() {
-       show "Checking %s configuration" "DHCP IPv6 Server"
-       out=`/sbin/dhcpd -t 2>&1`; rc=$?
-       if [ $rc -gt 0 ]; then
-               fail
-               echo >&2 "$out"
+check_device_up()
+{
+       local DEVICE=$1
+       if LC_ALL=C ip addr show dev $DEVICE | grep -q inet6; then
+               return 0
        else
-               ok
+               return 1
        fi
+}
+
+# configtest itself
+configtest() {
+       local rc=0
+       /sbin/dhcpd -6 -q -t -T || rc=$?
+
+       # 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/dhcpd6 ]; then
-               msg_starting "DHCP IPv6 Server"
-               daemon /sbin/dhcpd -6 $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 IPv6 Server"; busy
+               local out
+               out=$(configtest 2>&1)
                RETVAL=$?
-               [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd6
+               if [ $RETVAL = 0 ]; then
+                       ok
+               else
+                       fail
+               fi
+               [ "$out" ] && echo >&2 "$out"
        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 IPv6 Server"; fail
+                       nls 'Configuration test failed. See details with %s "checkconfig"' $0
+                       exit $RETVAL
+               fi
+       fi
+}
+
+start() {
+       # Check if the service is already running?
+       if [ -f /var/lock/subsys/dhcpd ]; then
                msg_already_running "DHCP IPv6 Server"
+               return
        fi
+
+       checkconfig
+       msg_starting "DHCP IPv6 Server"
+       daemon /sbin/dhcpd -6 -q $DHCPD_INTERFACES
+       RETVAL=$?
+       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd
 }
 
 stop() {
-       if [ -f /var/lock/subsys/dhcpd6 ]; then
-               msg_stopping "DHCP IPv6 Server"
-               killproc dhcpd
-               rm -f /var/run/dhcpd.pid /var/lock/subsys/dhcpd6 >/dev/null 2>&1
-       else
+       if [ ! -f /var/lock/subsys/dhcpd ]; then
                msg_not_running "DHCP IPv6 Server"
+               return
        fi
+
+       msg_stopping "DHCP IPv6 Server"
+       killproc --pidfile /var/run/dhcpd6.pid dhcpd
+       rm -f /var/run/dhcpd6.pid /var/lock/subsys/dhcpd >/dev/null 2>&1
 }
 
 condrestart() {
-       if [ -f /var/lock/subsys/dhcpd6 ]; then
-               stop
-               start
-       else
-               msg_not_running dhcpd
+       if [ ! -f /var/lock/subsys/dhcpd ]; then
+               msg_not_running "DHCP IPv6 Server"
                RETVAL=$1
+               return
        fi
+
+       checkconfig
+       stop
+       start
 }
 
 RETVAL=0
 # 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|configtest)
+       checkconfig 1
        ;;
   status)
-       status dhcpd
+       status --pidfile /var/run/dhcpd6.pid dhcpd
        exit $?
        ;;
   *)
This page took 0.056668 seconds and 4 git commands to generate.