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