]>
Commit | Line | Data |
---|---|---|
6d9124bb AM |
1 | #!/bin/sh |
2 | # DHCP IPv6 Server | |
3 | # | |
4 | # chkconfig: 345 80 20 | |
5 | # description: DHCP IPv6 Server | |
6 | ||
7 | # Source function library | |
8 | . /etc/rc.d/init.d/functions | |
9 | ||
10 | # Get network config | |
11 | . /etc/sysconfig/network | |
12 | ||
dc6d8725 ER |
13 | # Check that networking is up. |
14 | if ! is_yes "${IPV6_NETWORKING}"; then | |
15 | exit 0 | |
16 | fi | |
17 | ||
6d9124bb AM |
18 | # Get service config |
19 | [ -f /etc/sysconfig/dhcpd ] && . /etc/sysconfig/dhcpd | |
20 | ||
dc6d8725 ER |
21 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then |
22 | msg_network_down "DHCP IPv6 Server" | |
23 | exit 1 | |
6d9124bb AM |
24 | fi |
25 | ||
243ad503 ER |
26 | check_device_up() |
27 | { | |
28 | local DEVICE=$1 | |
29 | if LC_ALL=C ip addr show dev $DEVICE | grep -q inet6; then | |
30 | return 0 | |
6d9124bb | 31 | else |
243ad503 | 32 | return 1 |
6d9124bb | 33 | fi |
243ad503 ER |
34 | } |
35 | ||
36 | # configtest itself | |
37 | configtest() { | |
38 | local rc=0 | |
317075ff | 39 | /sbin/dhcpd -6 -t -T -cf /etc/dhcpd6.conf -pf /var/run/dhpcd6.pid || rc=$? |
243ad503 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 | ||
6d9124bb AM |
49 | return $rc |
50 | } | |
51 | ||
243ad503 | 52 | # wrapper for configtest |
8de0577b | 53 | checkconfig=-1 |
243ad503 ER |
54 | checkconfig() { |
55 | local details=${1:-0} | |
56 | ||
8de0577b | 57 | # run checkconfig only once |
317075ff | 58 | if [ $checkconfig -ne -1 ]; then |
8de0577b ER |
59 | return $checkconfig |
60 | fi | |
61 | ||
317075ff | 62 | if [ "$details" = "1" ]; then |
243ad503 ER |
63 | # run config test and display report (status action) |
64 | show "Checking %s configuration" "DHCP IPv6 Server"; busy | |
65 | local out | |
66 | out=$(configtest 2>&1) | |
8de0577b | 67 | checkconfig=$? |
317075ff | 68 | if [ $checkconfig -eq 0 ]; then |
243ad503 ER |
69 | ok |
70 | else | |
71 | fail | |
72 | fi | |
73 | [ "$out" ] && echo >&2 "$out" | |
ff8e99a3 | 74 | RETVAL=$checkconfig |
6d9124bb | 75 | else |
243ad503 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 | |
8de0577b | 79 | checkconfig=$? |
317075ff | 80 | if [ $checkconfig -ne 0 ]; then |
243ad503 ER |
81 | show "Checking %s configuration" "DHCP IPv6 Server"; fail |
82 | nls 'Configuration test failed. See details with %s "checkconfig"' $0 | |
8de0577b | 83 | exit $checkconfig |
243ad503 ER |
84 | fi |
85 | fi | |
86 | } | |
87 | ||
88 | start() { | |
89 | # Check if the service is already running? | |
3d74fc83 | 90 | if [ -f /var/lock/subsys/dhcpd6 ]; then |
6d9124bb | 91 | msg_already_running "DHCP IPv6 Server" |
243ad503 | 92 | return |
6d9124bb | 93 | fi |
243ad503 ER |
94 | |
95 | checkconfig | |
96 | msg_starting "DHCP IPv6 Server" | |
317075ff | 97 | daemon /sbin/dhcpd -6 -q -cf /etc/dhcpd6.conf -pf /var/run/dhpcd6.pid $DHCPD_INTERFACES |
243ad503 | 98 | RETVAL=$? |
3d74fc83 | 99 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd6 |
6d9124bb AM |
100 | } |
101 | ||
102 | stop() { | |
3d74fc83 | 103 | if [ ! -f /var/lock/subsys/dhcpd6 ]; then |
6d9124bb | 104 | msg_not_running "DHCP IPv6 Server" |
243ad503 | 105 | return |
6d9124bb | 106 | fi |
243ad503 ER |
107 | |
108 | msg_stopping "DHCP IPv6 Server" | |
109 | killproc --pidfile /var/run/dhcpd6.pid dhcpd | |
3d74fc83 | 110 | rm -f /var/run/dhcpd6.pid /var/lock/subsys/dhcpd6 >/dev/null 2>&1 |
6d9124bb AM |
111 | } |
112 | ||
113 | condrestart() { | |
3d74fc83 | 114 | if [ ! -f /var/lock/subsys/dhcpd6 ]; then |
243ad503 | 115 | msg_not_running "DHCP IPv6 Server" |
6d9124bb | 116 | RETVAL=$1 |
243ad503 | 117 | return |
6d9124bb | 118 | fi |
243ad503 ER |
119 | |
120 | checkconfig | |
121 | stop | |
122 | start | |
6d9124bb AM |
123 | } |
124 | ||
125 | RETVAL=0 | |
126 | # See how we were called. | |
127 | case "$1" in | |
128 | start) | |
6d9124bb AM |
129 | start |
130 | ;; | |
131 | stop) | |
132 | stop | |
133 | ;; | |
134 | restart) | |
243ad503 | 135 | checkconfig |
6d9124bb AM |
136 | stop |
137 | start | |
138 | ;; | |
139 | try-restart) | |
6d9124bb AM |
140 | condrestart 0 |
141 | ;; | |
142 | force-reload) | |
6d9124bb AM |
143 | condrestart 7 |
144 | ;; | |
243ad503 ER |
145 | checkconfig|configtest) |
146 | checkconfig 1 | |
6d9124bb AM |
147 | ;; |
148 | status) | |
c14d080f | 149 | status --pidfile /var/run/dhcpd6.pid dhcpd6 dhcpd |
6d9124bb AM |
150 | exit $? |
151 | ;; | |
152 | *) | |
153 | msg_usage "$0 {start|stop|restart|try-restart|force-reload|checkconfig|status}" | |
154 | exit 3 | |
155 | esac | |
156 | ||
157 | exit $RETVAL |