]> git.pld-linux.org Git - packages/dhcp.git/blob - dhcp6.init
- updated to 4.4.3-P1
[packages/dhcp.git] / dhcp6.init
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 # Check that networking is up.
14 if ! is_yes "${IPV6_NETWORKING}"; then
15         exit 0
16 fi
17
18 # Get service config
19 [ -f /etc/sysconfig/dhcpd ] && . /etc/sysconfig/dhcpd
20
21 if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
22         msg_network_down "DHCP IPv6 Server"
23         exit 1
24 fi
25
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
31         else
32                 return 1
33         fi
34 }
35
36 # configtest itself
37 configtest() {
38         local rc=0
39         /sbin/dhcpd -6 -t -T -cf /etc/dhcpd6.conf -pf /var/run/dhpcd6.pid || rc=$?
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
49         return $rc
50 }
51
52 # wrapper for configtest
53 checkconfig=-1
54 checkconfig() {
55         local details=${1:-0}
56
57         # run checkconfig only once
58         if [ $checkconfig -ne -1 ]; then
59                 return $checkconfig
60         fi
61
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)
67                 checkconfig=$?
68                 if [ $checkconfig -eq 0 ]; then
69                         ok
70                 else
71                         fail
72                 fi
73                 [ "$out" ] && echo >&2 "$out"
74                 RETVAL=$checkconfig
75         else
76                 # run config test and abort with nice message if failed
77                 # (for actions checking status before action).
78                 configtest >/dev/null 2>&1
79                 checkconfig=$?
80                 if [ $checkconfig -ne 0 ]; then
81                         show "Checking %s configuration" "DHCP IPv6 Server"; fail
82                         nls 'Configuration test failed. See details with %s "checkconfig"' $0
83                         exit $checkconfig
84                 fi
85         fi
86 }
87
88 start() {
89         # Check if the service is already running?
90         if [ -f /var/lock/subsys/dhcpd6 ]; then
91                 msg_already_running "DHCP IPv6 Server"
92                 return
93         fi
94
95         checkconfig
96         msg_starting "DHCP IPv6 Server"
97         daemon /sbin/dhcpd -6 -q -cf /etc/dhcpd6.conf -pf /var/run/dhpcd6.pid $DHCPD_INTERFACES
98         RETVAL=$?
99         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd6
100 }
101
102 stop() {
103         if [ ! -f /var/lock/subsys/dhcpd6 ]; then
104                 msg_not_running "DHCP IPv6 Server"
105                 return
106         fi
107
108         msg_stopping "DHCP IPv6 Server"
109         killproc --pidfile /var/run/dhcpd6.pid dhcpd
110         rm -f /var/run/dhcpd6.pid /var/lock/subsys/dhcpd6 >/dev/null 2>&1
111 }
112
113 condrestart() {
114         if [ ! -f /var/lock/subsys/dhcpd6 ]; then
115                 msg_not_running "DHCP IPv6 Server"
116                 RETVAL=$1
117                 return
118         fi
119
120         checkconfig
121         stop
122         start
123 }
124
125 RETVAL=0
126 # See how we were called.
127 case "$1" in
128   start)
129         start
130         ;;
131   stop)
132         stop
133         ;;
134   restart)
135         checkconfig
136         stop
137         start
138         ;;
139   try-restart)
140         condrestart 0
141         ;;
142   force-reload)
143         condrestart 7
144         ;;
145   checkconfig|configtest)
146         checkconfig 1
147         ;;
148   status)
149         status --pidfile /var/run/dhcpd6.pid dhcpd6 dhcpd
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
This page took 0.110315 seconds and 3 git commands to generate.