]>
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 | ||
13 | # Get service config | |
14 | [ -f /etc/sysconfig/dhcpd ] && . /etc/sysconfig/dhcpd | |
15 | ||
16 | # Check that networking is up. | |
17 | if is_yes "${NETWORKING}"; then | |
18 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then | |
19 | msg_network_down "DHCP IPv6 Server" | |
20 | exit 1 | |
21 | fi | |
22 | else | |
23 | exit 0 | |
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 | |
beb9a290 | 39 | /sbin/dhcpd -6 -pf /var/run/dhpcd6.pid -q -t -T || 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 ER |
57 | # run checkconfig only once |
58 | if [ "$checkconfig" != -1 ]; then | |
59 | return $checkconfig | |
60 | fi | |
61 | ||
243ad503 ER |
62 | if [ $details = 1 ]; then |
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 ER |
67 | checkconfig=$? |
68 | if [ $checkconfig = 0 ]; then | |
243ad503 ER |
69 | ok |
70 | else | |
71 | fail | |
72 | fi | |
73 | [ "$out" ] && echo >&2 "$out" | |
6d9124bb | 74 | else |
243ad503 ER |
75 | # run config test and abort with nice message if failed |
76 | # (for actions checking status before action). | |
77 | configtest >/dev/null 2>&1 | |
8de0577b ER |
78 | checkconfig=$? |
79 | if [ $checkconfig != 0 ]; then | |
243ad503 ER |
80 | show "Checking %s configuration" "DHCP IPv6 Server"; fail |
81 | nls 'Configuration test failed. See details with %s "checkconfig"' $0 | |
8de0577b | 82 | exit $checkconfig |
243ad503 ER |
83 | fi |
84 | fi | |
85 | } | |
86 | ||
87 | start() { | |
88 | # Check if the service is already running? | |
89 | if [ -f /var/lock/subsys/dhcpd ]; then | |
6d9124bb | 90 | msg_already_running "DHCP IPv6 Server" |
243ad503 | 91 | return |
6d9124bb | 92 | fi |
243ad503 ER |
93 | |
94 | checkconfig | |
95 | msg_starting "DHCP IPv6 Server" | |
beb9a290 | 96 | daemon /sbin/dhcpd -6 -pf /var/run/dhpcd6.pid -q $DHCPD_INTERFACES |
243ad503 ER |
97 | RETVAL=$? |
98 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd | |
6d9124bb AM |
99 | } |
100 | ||
101 | stop() { | |
243ad503 | 102 | if [ ! -f /var/lock/subsys/dhcpd ]; then |
6d9124bb | 103 | msg_not_running "DHCP IPv6 Server" |
243ad503 | 104 | return |
6d9124bb | 105 | fi |
243ad503 ER |
106 | |
107 | msg_stopping "DHCP IPv6 Server" | |
108 | killproc --pidfile /var/run/dhcpd6.pid dhcpd | |
109 | rm -f /var/run/dhcpd6.pid /var/lock/subsys/dhcpd >/dev/null 2>&1 | |
6d9124bb AM |
110 | } |
111 | ||
112 | condrestart() { | |
243ad503 ER |
113 | if [ ! -f /var/lock/subsys/dhcpd ]; then |
114 | msg_not_running "DHCP IPv6 Server" | |
6d9124bb | 115 | RETVAL=$1 |
243ad503 | 116 | return |
6d9124bb | 117 | fi |
243ad503 ER |
118 | |
119 | checkconfig | |
120 | stop | |
121 | start | |
6d9124bb AM |
122 | } |
123 | ||
124 | RETVAL=0 | |
125 | # See how we were called. | |
126 | case "$1" in | |
127 | start) | |
6d9124bb AM |
128 | start |
129 | ;; | |
130 | stop) | |
131 | stop | |
132 | ;; | |
133 | restart) | |
243ad503 | 134 | checkconfig |
6d9124bb AM |
135 | stop |
136 | start | |
137 | ;; | |
138 | try-restart) | |
6d9124bb AM |
139 | condrestart 0 |
140 | ;; | |
141 | force-reload) | |
6d9124bb AM |
142 | condrestart 7 |
143 | ;; | |
243ad503 ER |
144 | checkconfig|configtest) |
145 | checkconfig 1 | |
6d9124bb AM |
146 | ;; |
147 | status) | |
243ad503 | 148 | status --pidfile /var/run/dhcpd6.pid dhcpd |
6d9124bb AM |
149 | exit $? |
150 | ;; | |
151 | *) | |
152 | msg_usage "$0 {start|stop|restart|try-restart|force-reload|checkconfig|status}" | |
153 | exit 3 | |
154 | esac | |
155 | ||
156 | exit $RETVAL |