15db47c18f7d295e78efa9ec0ee873432bb5370a
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / dnsmasq
1 #!/bin/sh
2 ########################################################################
3 # Begin $rc_base/init.d/dnsmasq
4 #
5 # Description : dnsmasq init script
6 #
7 # Authors : Michael Tremer - mitch@ipfire.org
8 #
9 # Version : 01.00
10 #
11 # Notes :
12 #
13 ########################################################################
14
15 . /etc/sysconfig/rc
16 . ${rc_functions}
17
18 # Pull custom configuration file
19 if [ -e "/etc/sysconfig/dnsmasq" ]; then
20 . /etc/sysconfig/dnsmasq
21 fi
22
23 SHOW_SRV=1
24
25 function dns_forward_args() {
26 local file="${1}"
27
28 # Do nothing if file is empty.
29 [ -s "${file}" ] || return
30
31 local cmdline
32
33 local enabled zone server remark
34 while IFS="," read -r enabled zone server remark; do
35 # Line must be enabled.
36 [ "${enabled}" = "on" ] || continue
37
38 cmdline="${cmdline} --server=/${zone}/${server}"
39 done < ${file}
40
41 echo "${cmdline}"
42 }
43
44
45 case "${1}" in
46 start)
47 # kill already running copy of dnsmasq...
48 killproc /usr/sbin/dnsmasq 2>&1 > /dev/null
49
50 boot_mesg "Starting Domain Name Service Proxy..."
51
52 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
53 ARGS="$CUSTOM_ARGS"
54 [ "$DOMAIN_NAME_GREEN" != "" ] && ARGS="-s $DOMAIN_NAME_GREEN"
55
56 echo > /var/ipfire/red/resolv.conf # Clear it
57 if [ -e "/var/ipfire/red/dns1" ]; then
58 DNS1=$(cat /var/ipfire/red/dns1 2>/dev/null)
59 if [ ! -z ${DNS1} ]; then
60 echo "nameserver ${DNS1}" >> /var/ipfire/red/resolv.conf
61 fi
62 fi
63 if [ -e "/var/ipfire/red/dns2" ]; then
64 DNS2=$(cat /var/ipfire/red/dns2 2>/dev/null)
65 if [ ! -z ${DNS2} ]; then
66 echo "nameserver ${DNS2}" >> /var/ipfire/red/resolv.conf
67 fi
68 fi
69 [ -e "/var/ipfire/red/active" ] && ARGS="$ARGS -r /var/ipfire/red/resolv.conf"
70
71 ARGS="$ARGS --domain=`cat /var/ipfire/main/settings |grep DOMAIN |cut -d = -f 2`"
72
73 # Add custom forward dns zones.
74 ARGS="${ARGS} $(dns_forward_args /var/ipfire/dnsforward/config)"
75
76 loadproc /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases $ARGS
77
78 if [ "${SHOW_SRV}" -eq 1 ] && [ "${DNS1}" != "" -o "${DNS2}" != "" ]; then
79 boot_mesg "Using DNS server(s): ${DNS1} ${DNS2}"
80 boot_mesg_flush
81 fi
82 ;;
83
84 stop)
85 boot_mesg "Stopping Domain Name Service Proxy..."
86 killproc /usr/sbin/dnsmasq
87 ;;
88
89 restart)
90 ${0} stop
91 sleep 1
92 ${0} start
93 ;;
94
95 status)
96 statusproc /usr/sbin/dnsmasq
97 ;;
98
99 *)
100 echo "Usage: ${0} {start|stop|restart|status}"
101 exit 1
102 ;;
103 esac
104
105 # End $rc_base/init.d/dnsmasq