forked from greearb/dhcp-ct
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dhcpd.init
150 lines (128 loc) · 2.89 KB
/
dhcpd.init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: dhcpd
# Default-Start:
# Default-Stop:
# Should-Start:
# Required-Start: $network
# Required-Stop:
# Short-Description: Start and stop the DHCP server
# Description: dhcpd provides the Dynamic Host Configuration Protocol (DHCP)
# server.
### END INIT INFO
#
# The fields below are left around for legacy tools (will remove later).
#
# chkconfig: - 65 35
# description: dhcpd provides the Dynamic Host Configuration Protocol (DHCP) \
# server
# processname: dhcpd
# config: /etc/dhcp/dhcpd.conf
# config: /var/lib/dhcpd/dhcpd.leases
# pidfile: /var/run/dhcpd.pid
. /etc/rc.d/init.d/functions
RETVAL=0
prog=dhcpd
exec=/usr/sbin/dhcpd
lockfile=/var/lock/subsys/dhcpd
pidfile=/var/run/dhcpd.pid
statedir=/var/lib/dhcpd
[ -f /etc/sysconfig/dhcpd ] && . /etc/sysconfig/dhcpd
# if the user specified a different config file, make sure we reference it
findConfig() {
for arg in $DHCPDARGS ; do
if [ "$found" = 1 ]; then
[ -f "$arg" ] && echo "$arg"
return
fi
if [ "$arg" = "-cf" ]; then
found=1
continue
fi
done
echo "/etc/dhcp/dhcpd.conf"
}
config="$(findConfig "$DHCPDARGS")"
if [ ! -f $statedir/dhcpd.leases ] ; then
mkdir -p $statedir
touch $statedir/dhcpd.leases
[ -x /sbin/restorecon ] && [ -d /selinux ] && /sbin/restorecon $statedir/dhcpd.leases >/dev/null 2>&1
fi
configtest() {
[ -x $exec ] || return 5
[ -f $config ] || return 6
$exec -q -t -cf $config
RETVAL=$?
if [ $RETVAL -eq 1 ]; then
$exec -t -cf $config
else
echo "Syntax: OK" >&2
fi
return $RETVAL
}
rh_status() {
status -p $pidfile -l $(basename $lockfile) $exec
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
start() {
[ `id -u` -eq 0 ] || return 4
[ -x $exec ] || return 5
[ -f $config ] || return 6
rh_status_q && return 0
echo -n $"Starting $prog: "
daemon --pidfile=$pidfile $exec $DHCPDARGS 2>/dev/null
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $lockfile
return $RETVAL
}
stop() {
[ `id -u` -eq 0 ] || return 4
rh_status_q || return 0
echo -n $"Shutting down $prog: "
killproc -p $pidfile $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
return $RETVAL
}
usage() {
echo $"Usage: $0 {start|stop|restart|force-reload|condrestart|try-restart|configtest|status}"
}
if [ $# -gt 1 ]; then
exit 2
fi
case "$1" in
start)
start
;;
stop)
stop
;;
restart|force-reload)
stop ; start
;;
condrestart|try-restart)
rh_status_q || exit 0
stop ; start
;;
reload)
usage
# unimplemented feature
exit 3
;;
configtest)
configtest
;;
status)
rh_status
;;
*)
usage
exit 2
;;
esac
exit $?