]> git.pld-linux.org Git - packages/dhcp.git/blobdiff - dhcp.init
- updated to 4.4.3-P1
[packages/dhcp.git] / dhcp.init
index b3f7afebd3b61c902cf490b09b31d56361f760d2..1e59529a3001d91bfbc50684d698c0a25096d388 100644 (file)
--- a/dhcp.init
+++ b/dhcp.init
 # Get network config
 . /etc/sysconfig/network
 
+# Check that networking is up.
+if ! is_yes "${IPV4_NETWORKING}"; then
+       exit 0
+fi
+
 # Get service config
-[ -f /etc/sysconfig/dhcp ] && . /etc/sysconfig/dhcp
+[ -f /etc/sysconfig/dhcpd ] && . /etc/sysconfig/dhcpd
 
-# Check that networking is up.
-[ "${NETWORKING}" = "no" ] && echo "Error: Networking is down" && exit 0
+if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
+       msg_network_down "DHCP Server"
+       exit 1
+fi
 
+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
+}
 
-# See how we were called.
-case "$1" in
-  start)
+# configtest itself
+configtest() {
+       local rc=0
+       /sbin/dhcpd -4 -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
+}
+
+# wrapper for configtest
+checkconfig=-1
+checkconfig() {
+       local details=${1:-0}
+
+       # run checkconfig only once
+       if [ $checkconfig -ne -1 ]; then
+               return $checkconfig
+       fi
+
+       if [ "$details" = "1" ]; then
+               # run config test and display report (status action)
+               show "Checking %s configuration" "DHCP Server"; busy
+               local out
+               out=$(configtest 2>&1)
+               checkconfig=$?
+               if [ $checkconfig -eq 0 ]; then
+                       ok
+               else
+                       fail
+               fi
+               [ "$out" ] && echo >&2 "$out"
+               RETVAL=$checkconfig
+       else
+               # run config test and abort with nice message if failed
+               # (for actions checking status before action).
+               configtest >/dev/null 2>&1
+               checkconfig=$?
+               if [ $checkconfig -ne 0 ]; then
+                       show "Checking %s configuration" "DHCP Server"; fail
+                       nls 'Configuration test failed. See details with %s "checkconfig"' $0
+                       exit $checkconfig
+               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 -4 -q $DHCPD_INTERFACES
+       RETVAL=$?
+       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd
+}
+
+stop() {
        if [ ! -f /var/lock/subsys/dhcpd ]; then
-               show Starting dhcpd
-               daemon dhcpd
-       else
-               echo "dhcpd already is running"
+               msg_not_running "DHCP Server"
+               return
        fi
-       touch /var/lock/subsys/dhcpd
-       show Starting DHCP Server
-       daemon dhcpd
-       touch /var/lock/subsys/dhcpd
+
+       msg_stopping "DHCP Server"
+       killproc --pidfile /var/run/dhcpd.pid dhcpd
+       rm -f /var/run/dhcpd.pid /var/lock/subsys/dhcpd >/dev/null 2>&1
+}
+
+condrestart() {
+       if [ ! -f /var/lock/subsys/dhcpd ]; then
+               msg_not_running "DHCP Server"
+               RETVAL=$1
+               return
+       fi
+
+       checkconfig
+       stop
+       start
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+       start
        ;;
   stop)
-       show Stopping DHCP Server
-       killproc dhcpd
-       rm -f /var/run/dhcpd.pid
-       rm -f /var/lock/subsys/dhcpd
+       stop
+       ;;
+  restart)
+       checkconfig
+       stop
+       start
        ;;
-  restart|reload)
-       $0 stop
-       $0 start
+  try-restart)
+       condrestart 0
+       ;;
+  force-reload)
+       condrestart 7
+       ;;
+  checkconfig|configtest)
+       checkconfig 1
        ;;
   status)
-       status dhcpd
+       status --pidfile /var/run/dhcpd.pid dhcpd
+       exit $?
        ;;
   *)
-       echo "Usage: $0 {start|stop|restart|reload|status}"
-       exit 1
+       msg_usage "$0 {start|stop|restart|try-restart|force-reload|checkconfig|status}"
+       exit 3
 esac
 
-exit 0
-
+exit $RETVAL
This page took 0.177616 seconds and 4 git commands to generate.