#!/bin/bash
+# $Id$
+# $URL$
#
-# priority: 850
+# priority: 950
#
# Start local DNS server to provide minimal DNS forward resolution for
# ourselves and our nodes.
# Mark Huang <mlhuang@cs.princeton.edu>
# Copyright (C) 2006 The Trustees of Princeton University
#
-# $Id: mail,v 1.2 2006/04/25 21:18:19 mlhuang Exp $
-#
# Source function library and configuration
. /etc/plc.d/functions
. /etc/planetlab/plc_config
+SIGNATURE="; generated by /etc/plc.d/dns --- DO NOT REMOVE THIS TEXT!"
+
+# Be verbose
+set -x
+
case "$1" in
start)
- if [ "$PLC_DNS_ENABLED" != "1" ] ; then
- exit 0
+ if [ $PLC_DNS_ENABLED -eq 1 ] ; then
+ MESSAGE="Starting DNS server"
+ dialog "$MESSAGE"
+
+ dns-config
+ check
+ fi
+
+ # Set up nameservers
+ if [ -n "$PLC_NET_DNS1" -o -n "$PLC_NET_DNS2" ] ; then
+ MESSAGE="Configuring resolv.conf"
+ dialog "$MESSAGE"
+
+ rfile=$(mktemp)
+ (
+ echo $SIGNATURE
+ [ -n "$PLC_NET_DNS1" ] && echo "nameserver $PLC_NET_DNS1"
+ [ -n "$PLC_NET_DNS2" -a "$PLC_NET_DNS1" != "$PLC_NET_DNS2" ] && echo "nameserver $PLC_NET_DNS2"
+ ) > $rfile
+
+ if [ $PLC_DNS_ENABLED -eq 1 ] ; then
+ ourfile=$(grep "$SIGNATURE" /etc/resolv.conf| wc -l)
+ if [ $ourfile -eq 0 ] ; then
+ cp /etc/resolv.conf /etc/plc_resolv.conf
+ fi
+ else
+ cp /etc/resolv.conf /etc/resolv_plc.backup
+ fi
+ mv -f $rfile /etc/resolv.conf
+ chmod 444 /etc/resolv.conf
fi
- MESSAGE=$"Starting DNS server"
- dialog "$MESSAGE"
-
- # From the default dnsmasq.conf configuration file:
- #
- # The [domain-needed and bogus-priv] options make you a better
- # netizen, since they tell dnsmasq to filter out queries which
- # the public DNS cannot answer, and which load the servers
- # (especially the root servers) uneccessarily.
- #
- # The api-config bootstrap script writes node hostnames to
- # /etc/plc_hosts.
- #
- cat >/etc/dnsmasq.conf <<EOF
-domain-needed
-bogus-priv
-addn-hosts=/etc/plc_hosts
-EOF
-
- plc_daemon dnsmasq
- check
+ if [ $PLC_DNS_ENABLED -eq 1 ] ; then
+ plc_daemon dnsmasq
+ check
+ fi
result "$MESSAGE"
;;
stop)
- MESSAGE=$"Stopping DNS server"
- dialog "$MESSAGE"
+ if [ $PLC_DNS_ENABLED -eq 1 ] ; then
+ MESSAGE=$"Reverting /etc/resolv.conf"
+ dialog "$MESSAGE"
+ if [ -f "/etc/plc_resolv.conf" ] ; then
+ ourfile=$(grep "$SIGNATURE" /etc/plc_resolv.conf| wc -l)
+ if [ $ourfile -ne 0 ] ; then
+ dialog "WARNING: original /etc/resolv.conf was generated by etc/plc.d/dns"
+ fi
+ mv -f /etc/plc_resolv.conf /etc/resolv.conf
+ fi
+ check
+ result ""
+ MESSAGE=$"Removing /etc/plc_hosts"
+ dialog "$MESSAGE"
+ [ -f "/etc/plc_hosts" ] && rm -f /etc/plc_hosts
+ result ""
+ fi
+ if [ $PLC_DNS_ENABLED -eq 0 -a -f "/etc/resolv_plc.backup" ] ; then
+ MESSAGE="Restoring /etc/resolv.conf"
+ dialog "$MESSAGE"
+ mv -f /etc/resolv_plc.backup /etc/resolv.conf
+ result ""
+ fi
- killproc plc_dnsmasq
- check
+ if [ $PLC_DNS_ENABLED -eq 1 ] ; then
+ MESSAGE="Stopping DNS server"
+ dialog "$MESSAGE"
+ killproc plc_dnsmasq
+ check
+ result ""
+ fi
- result "$MESSAGE"
;;
esac