12a84521673d4d6bf2fa0a1d12880fcce3fcc376
[packages.git] / ipv6 / ahcpd / files / ahcpd.init
1 #!/bin/sh /etc/rc.common
2
3 START=71
4
5 pidfile=/var/run/ahcpd.pid
6 addif() {
7         config_get ifname $1 ifname
8         append interfaces "$ifname"
9 }
10
11 ahcpd_config() {
12         local cfg="$1"
13         interfaces=
14         config_list_foreach $cfg interface addif
15         [ -z "$interfaces" ] && return 0
16         config_get_bool no_config "$cfg" no_config 0
17         config_get_bool ipv4_only "$cfg" ipv4_only 0
18         config_get_bool ipv6_only "$cfg" ipv6_only 0
19         config_get_bool no_dns "$cfg" no_dns 0
20         if [ "$no_config" -eq 0 ]; then
21                 unset no_config
22         fi
23         if [ "$ipv4_only" -eq 0 ]; then
24                 unset ipv4_only
25         fi
26         if [ "$ipv6_only" -eq 0 ]; then
27                 unset ipv6_only
28         fi
29         if [ "$no_dns" -eq 0 ]; then
30                 unset no_dns
31         fi
32         if [ -e $pidfile ] ; then
33                 echo "$pidfile exists -- not starting ahcpd." >&2
34         else
35                 /usr/sbin/ahcpd -s /usr/lib/ahcp/ahcp-config.sh -D -I $pidfile \
36                 ${ipv4_only:+-4} ${ipv6_only:+-6} ${no_dns:+-N} ${no_config:+-n} \
37                 $interfaces
38         fi
39 }
40
41 start() {
42         include /lib/network
43         scan_interfaces
44         config_load ahcpd
45         mkdir -p /var/lib
46         config_foreach ahcpd_config ahcpd
47 }
48
49 stop() {
50         [ -e $pidfile ] && kill $(cat $pidfile)
51         [ -e $pidfile ] && sleep 2
52         [ -e $pidfile ] && sleep 4
53         [ -e $pidfile ] && echo "Failed to stop ahcpd ($pidfile still exists)."
54 }