1b2c0c206dc51eb04f0b4cc754bcf16742ceafd5
[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 case "${1}" in
26         start)
27                 # kill already running copy of dnsmasq...
28                 killproc /usr/sbin/dnsmasq 2>&1 > /dev/null
29
30                 boot_mesg "Starting Domain Name Service Proxy..."
31                 
32                 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
33                 ARGS=
34                 [ "$DOMAIN_NAME_GREEN" != "" ] && ARGS="-s $DOMAIN_NAME_GREEN"
35                 
36                 echo > /var/ipfire/red/resolv.conf # Clear it
37                 if [ -e "/var/ipfire/red/dns1" ]; then
38                     DNS1=$(cat /var/ipfire/red/dns1 2>/dev/null)
39                     if [ ! -z ${DNS1} ]; then
40                         echo "nameserver ${DNS1}" >> /var/ipfire/red/resolv.conf
41                     fi
42                 fi
43                 if [ -e "/var/ipfire/red/dns2" ]; then
44                     DNS2=$(cat /var/ipfire/red/dns2 2>/dev/null)
45                     if [ ! -z ${DNS2} ]; then
46                         echo "nameserver ${DNS2}" >> /var/ipfire/red/resolv.conf
47                     fi
48                 fi
49                 [ -e "/var/ipfire/red/active" ] && ARGS="$ARGS -r /var/ipfire/red/resolv.conf"
50                 
51                 ARGS="$ARGS --domain=`cat /var/ipfire/main/settings |grep DOMAIN |cut -d = -f 2`"
52                 ARGS="$ARGS $CUSTOM_ARGS"
53
54                 loadproc /usr/sbin/dnsmasq -l /var/state/dhcp/dhcpd.leases $ARGS
55                 
56                 if [ "${SHOW_SRV}" -eq 1 ] && [ "${DNS1}" != "" -o "${DNS2}" != "" ]; then
57                     boot_mesg "Using DNS server(s): ${DNS1} ${DNS2}"
58                     boot_mesg_flush
59                 fi
60                 ;;
61
62         stop)
63                 boot_mesg "Stopping Domain Name Service Proxy..."
64                 killproc /usr/sbin/dnsmasq
65                 ;;
66
67         restart)
68                 ${0} stop
69                 sleep 1
70                 ${0} start
71                 ;;
72
73         status)
74                 statusproc /usr/sbin/dnsmasq
75                 ;;
76
77         *)
78                 echo "Usage: ${0} {start|stop|restart|status}"
79                 exit 1
80                 ;;
81 esac
82
83 # End $rc_base/init.d/dnsmasq