]> git.pld-linux.org Git - packages/dhcp.git/blame - dhcp6.init
- skip if appropriate network family is disabled
[packages/dhcp.git] / dhcp6.init
CommitLineData
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.
86fe3b99 17if is_yes "${IPV6_NETWORKING}"; then
6d9124bb
AM
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
22else
23 exit 0
24fi
25
243ad503
ER
26check_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
37configtest() {
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 53checkconfig=-1
243ad503
ER
54checkconfig() {
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"
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
ER
79 checkconfig=$?
80 if [ $checkconfig != 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
88start() {
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"
beb9a290 97 daemon /sbin/dhcpd -6 -pf /var/run/dhpcd6.pid -q $DHCPD_INTERFACES
243ad503 98 RETVAL=$?
3d74fc83 99 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dhcpd6
6d9124bb
AM
100}
101
102stop() {
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
113condrestart() {
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
125RETVAL=0
126# See how we were called.
127case "$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
155esac
156
157exit $RETVAL
This page took 0.061969 seconds and 4 git commands to generate.