]> git.pld-linux.org Git - packages/dhcp.git/blame - dhcp.init
- updated to 4.4.3-P1
[packages/dhcp.git] / dhcp.init
CommitLineData
bdeb1016 1#!/bin/sh
2# DHCP Server
3#
c01c2dc3 4# chkconfig: 345 80 20
5# description: DHCP Server
bdeb1016 6
c01c2dc3 7# Source function library
bdeb1016 8. /etc/rc.d/init.d/functions
9
c01c2dc3 10# Get network config
11. /etc/sysconfig/network
12
dc6d8725
ER
13# Check that networking is up.
14if ! is_yes "${IPV4_NETWORKING}"; then
15 exit 0
16fi
17
c01c2dc3 18# Get service config
8e1f3361 19[ -f /etc/sysconfig/dhcpd ] && . /etc/sysconfig/dhcpd
c01c2dc3 20
dc6d8725
ER
21if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
22 msg_network_down "DHCP Server"
23 exit 1
b7aa684c 24fi
c01c2dc3 25
fb812d76
ER
26check_device_up()
27{
28 local DEVICE=$1
29 if LC_ALL=C ip addr show dev $DEVICE | grep -q inet; then
30 return 0
31 else
32 return 1
33 fi
34}
35
36# configtest itself
37configtest() {
aa4eeeb6 38 local rc=0
317075ff 39 /sbin/dhcpd -4 -t -T || rc=$?
fb812d76
ER
40
41 # check if interfaces specified exist and have addresses
42 for i in $DHCPD_INTERFACES; do
43 if ! check_device_up $i; then
44 echo >&2 "Device '$i' does not exist or has no address configured"
45 rc=1
46 fi
47 done
48
9a0037f8
ER
49 return $rc
50}
51
aa4eeeb6 52# wrapper for configtest
46107bb2 53checkconfig=-1
fb812d76
ER
54checkconfig() {
55 local details=${1:-0}
56
46107bb2 57 # run checkconfig only once
317075ff 58 if [ $checkconfig -ne -1 ]; then
46107bb2
ER
59 return $checkconfig
60 fi
61
317075ff 62 if [ "$details" = "1" ]; then
fb812d76 63 # run config test and display report (status action)
aa4eeeb6
ER
64 show "Checking %s configuration" "DHCP Server"; busy
65 local out
66 out=$(configtest 2>&1)
46107bb2 67 checkconfig=$?
317075ff 68 if [ $checkconfig -eq 0 ]; then
aa4eeeb6
ER
69 ok
70 else
71 fail
72 fi
73 [ "$out" ] && echo >&2 "$out"
46107bb2 74 RETVAL=$checkconfig
c01c2dc3 75 else
fb812d76
ER
76 # run config test and abort with nice message if failed
77 # (for actions checking status before action).
78 configtest >/dev/null 2>&1
46107bb2 79 checkconfig=$?
317075ff 80 if [ $checkconfig -ne 0 ]; then
fb812d76 81 show "Checking %s configuration" "DHCP Server"; fail
aa4eeeb6 82 nls 'Configuration test failed. See details with %s "checkconfig"' $0
46107bb2 83 exit $checkconfig
fb812d76
ER
84 fi
85 fi
86}
87
88start() {
89 # Check if the service is already running?
90 if [ -f /var/lock/subsys/dhcpd ]; then
456e0d36 91 msg_already_running "DHCP Server"
fb812d76 92 return
c01c2dc3 93 fi
fb812d76
ER
94
95 checkconfig
96 msg_starting "DHCP Server"
f18d2ef7 97 daemon /sbin/dhcpd -4 -q $DHCPD_INTERFACES
fb812d76
ER
98 RETVAL=$?
99 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd
5fe17ae7
ER
100}
101
102stop() {
fb812d76 103 if [ ! -f /var/lock/subsys/dhcpd ]; then
456e0d36 104 msg_not_running "DHCP Server"
fb812d76 105 return
915cd150 106 fi
fb812d76
ER
107
108 msg_stopping "DHCP Server"
f18d2ef7 109 killproc --pidfile /var/run/dhcpd.pid dhcpd
fb812d76 110 rm -f /var/run/dhcpd.pid /var/lock/subsys/dhcpd >/dev/null 2>&1
5fe17ae7
ER
111}
112
28a279e1 113condrestart() {
f18d2ef7
ER
114 if [ ! -f /var/lock/subsys/dhcpd ]; then
115 msg_not_running "DHCP Server"
28a279e1 116 RETVAL=$1
f18d2ef7 117 return
28a279e1 118 fi
f18d2ef7
ER
119
120 checkconfig
121 stop
122 start
28a279e1
JB
123}
124
5fe17ae7
ER
125RETVAL=0
126# See how we were called.
127case "$1" in
128 start)
9b690214 129 start
5fe17ae7
ER
130 ;;
131 stop)
9b690214 132 stop
bdeb1016 133 ;;
9c9075f5 134 restart)
fb812d76 135 checkconfig
5fe17ae7
ER
136 stop
137 start
bdeb1016 138 ;;
28a279e1 139 try-restart)
28a279e1
JB
140 condrestart 0
141 ;;
142 force-reload)
28a279e1
JB
143 condrestart 7
144 ;;
aa4eeeb6 145 checkconfig|configtest)
fb812d76 146 checkconfig 1
9a0037f8 147 ;;
bdeb1016 148 status)
f18d2ef7 149 status --pidfile /var/run/dhcpd.pid dhcpd
915cd150 150 exit $?
bdeb1016 151 ;;
152 *)
28a279e1 153 msg_usage "$0 {start|stop|restart|try-restart|force-reload|checkconfig|status}"
915cd150 154 exit 3
bdeb1016 155esac
156
a5333732 157exit $RETVAL
This page took 0.140958 seconds and 4 git commands to generate.