]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/init.d/dnsmasq
dnsmasq: fix initskript
[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 CACHE_SIZE=2500
19 ENABLE_DNSSEC=1
20 SHOW_SRV=1
21 TRUST_ANCHOR=".,19036,8,2,49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5"
22 TIMESTAMP_FILE="/var/ipfire/dns/dnssec-timestamp"
23
24 # Pull custom configuration file
25 if [ -e "/etc/sysconfig/dnsmasq" ]; then
26 . /etc/sysconfig/dnsmasq
27 fi
28
29 function dnssec_args() {
30 local cmdline="--dnssec --dnssec-timestamp ${TIMESTAMP_FILE}"
31
32 if [ -n "${TRUST_ANCHOR}" ]; then
33 cmdline="${cmdline} --trust-anchor=${TRUST_ANCHOR}"
34 fi
35
36 echo "${cmdline}"
37 }
38
39 function dns_forward_args() {
40 local file="${1}"
41
42 # Do nothing if file is empty.
43 [ -s "${file}" ] || return
44
45 local cmdline
46
47 local enabled zone server remark
48 while IFS="," read -r enabled zone server remark; do
49 # Line must be enabled.
50 [ "${enabled}" = "on" ] || continue
51
52 cmdline="${cmdline} --server=/${zone}/${server}"
53 done < ${file}
54
55 echo "${cmdline}"
56 }
57
58 case "${1}" in
59 start)
60 # kill already running copy of dnsmasq...
61 killproc /usr/sbin/dnsmasq 2>&1 > /dev/null
62
63 boot_mesg "Starting Domain Name Service Proxy..."
64
65 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
66 ARGS="$CUSTOM_ARGS"
67 [ "$DOMAIN_NAME_GREEN" != "" ] && ARGS="$ARGS -s $DOMAIN_NAME_GREEN"
68
69 echo > /var/ipfire/red/resolv.conf # Clear it
70 if [ -e "/var/ipfire/red/dns1" ]; then
71 DNS1=$(cat /var/ipfire/red/dns1 2>/dev/null)
72 if [ ! -z ${DNS1} ]; then
73 echo "nameserver ${DNS1}" >> /var/ipfire/red/resolv.conf
74 fi
75 fi
76 if [ -e "/var/ipfire/red/dns2" ]; then
77 DNS2=$(cat /var/ipfire/red/dns2 2>/dev/null)
78 if [ ! -z ${DNS2} ]; then
79 echo "nameserver ${DNS2}" >> /var/ipfire/red/resolv.conf
80 fi
81 fi
82 [ -e "/var/ipfire/red/active" ] && ARGS="$ARGS -r /var/ipfire/red/resolv.conf"
83
84 ARGS="$ARGS --domain=`cat /var/ipfire/main/settings |grep DOMAIN |cut -d = -f 2`"
85
86 # Add custom forward dns zones.
87 ARGS="${ARGS} $(dns_forward_args /var/ipfire/dnsforward/config)"
88
89 # Enabled DNSSEC validation
90 if [ "${ENABLE_DNSSEC}" -eq 1 ]; then
91 ARGS="${ARGS} $(dnssec_args)"
92 fi
93
94 if [ -n "${CACHE_SIZE}" ]; then
95 ARGS="${ARGS} --cache-size=${CACHE_SIZE}"
96 fi
97
98 loadproc /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases $ARGS
99
100 if [ "${SHOW_SRV}" -eq 1 ] && [ "${DNS1}" != "" -o "${DNS2}" != "" ]; then
101 boot_mesg "Using DNS server(s): ${DNS1} ${DNS2}"
102 boot_mesg_flush
103 fi
104 ;;
105
106 stop)
107 boot_mesg "Stopping Domain Name Service Proxy..."
108 killproc /usr/sbin/dnsmasq
109 ;;
110
111 restart)
112 ${0} stop
113 sleep 1
114 ${0} start
115 ;;
116
117 status)
118 statusproc /usr/sbin/dnsmasq
119 ;;
120
121 *)
122 echo "Usage: ${0} {start|stop|restart|status}"
123 exit 1
124 ;;
125 esac
126
127 # End $rc_base/init.d/dnsmasq