5
set +e # Don't exit on error status
4
7
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
5
8
DAEMON=/usr/sbin/dnsmasq
7
DESC="caching dns forwarder"
9
# configuration options are now in /etc/default/dnsmasq
11
if [ -f /etc/default/$NAME ]; then
15
test -f $DAEMON || exit 0
10
DESC="DNS forwarder and DHCP server"
12
# Most configuration options in /etc/default/dnsmasq are deprecated
15
if [ -r /etc/default/$NAME ]; then
19
test -x $DAEMON || exit 0
22
# If the resolvconf package is installed then use the resolv conf file
23
# that it provides as the default. Otherwise use /etc/resolv.conf as
26
# This setting can be overridden by setting the RESOLV_CONF environment
27
# variable in /etc/default/dnsmasq or by including a resolv-file
28
# line in /etc/dnsmasq.conf .
30
if [ ! "$RESOLV_CONF" ] &&
31
[ -x /sbin/resolvconf ]
33
RESOLV_CONF=/var/run/dnsmasq/resolv.conf
36
for INTERFACE in $DNSMASQ_INTERFACE; do
37
DNSMASQ_INTERFACES="$DNSMASQ_INTERFACES -i $INTERFACE"
43
# 0 if daemon has been started
44
# 1 if daemon was already running
45
# 2 if daemon could not be started
46
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid --exec $DAEMON --test > /dev/null || return 1
47
start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid --exec $DAEMON -- \
48
${MAILHOSTNAME:+ -m $MAILHOSTNAME} \
49
${MAILTARGET:+ -t $MAILTARGET} \
50
${DNSMASQ_USER:+ -u $DNSMASQ_USER} \
51
${DNSMASQ_INTERFACE:+ $DNSMASQ_INTERFACES} \
52
${DHCP_LEASE:+ -l $DHCP_LEASE} \
53
${DOMAIN_SUFFIX:+ -s $DOMAIN_SUFFIX} \
54
${RESOLV_CONF:+ -r $RESOLV_CONF} \
55
${CACHESIZE:+ -c $CACHESIZE} \
56
${DNSMASQ_OPTS:+ $DNSMASQ_OPTS} \
62
if [ -x /sbin/resolvconf ] ; then
63
echo "nameserver 127.0.0.1" | /sbin/resolvconf -a lo.$NAME
71
# 0 if daemon has been stopped
72
# 1 if daemon was already stopped
73
# 2 if daemon could not be stopped
74
# other if a failure occurred
75
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile /var/run/$NAME.pid --name $NAME
77
[ "$RETVAL" = 2 ] && return 2
78
# Wait for children to finish too
79
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
80
[ "$?" = 2 ] && return 2
81
rm -f /var/run/$NAME.pid # Doesn't delete its own pidfile
87
if [ -x /sbin/resolvconf ] ; then
88
/sbin/resolvconf -d lo.$NAME
21
echo -n "Starting $DESC: "
22
start-stop-daemon --start --quiet --pidfile \
23
/var/run/$NAME.pid --exec $DAEMON -- \
24
${MAILHOSTNAME:+ -m $MAILHOSTNAME} \
25
${MAILTARGET:+ -t $MAILTARGET} \
26
${DNSMASQ_USER:+ -u $DNSMASQ_USER} \
27
${DNSMASQ_INTERFACE:+ -i $DNSMASQ_INTERFACE} \
28
${DHCP_LEASE:+ -l $DHCP_LEASE} \
29
${DOMAIN_SUFFIX:+ -s $DOMAIN_SUFFIX} \
30
${RESOLV_CONF:+ -r $RESOLV_CONF}
95
echo -n "Starting $DESC: $NAME"
104
echo " (already running)."
34
echo -n "Stopping $DESC: "
35
start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
115
echo -n "Stopping $DESC: $NAME"
118
0) echo "." ; exit 0 ;;
119
1) echo " (not running)." ; exit 0 ;;
120
*) echo " (failed)." ; exit 1 ;;
40
echo "Reloading $DESC configuration files."
41
start-stop-daemon --stop --signal 1 --quiet --pidfile \
42
/var/run/$NAME.pid --exec $DAEMON
45
echo -n "Restarting $DESC: "
46
start-stop-daemon --stop --quiet --pidfile \
47
/var/run/$NAME.pid --exec $DAEMON
49
start-stop-daemon --start --quiet --pidfile \
50
/var/run/$NAME.pid --exec $DAEMON -- \
51
${MAILHOSTNAME:+ -m $MAILHOSTNAME} \
52
${MAILTARGET:+ -t $MAILTARGET} \
53
${DNSMASQ_USER:+ -u $DNSMASQ_USER} \
54
${DNSMASQ_INTERFACE:+ -i $DNSMASQ_INTERFACE} \
55
${DHCP_LEASE:+ -l $DHCP_LEASE} \
56
${DOMAIN_SUFFIX:+ -s $DOMAIN_SUFFIX} \
57
${RESOLV_CONF:+ -r $RESOLV_CONF}
123
restart|force-reload)
125
echo -n "Restarting $DESC: $NAME"
137
echo " (failed -- old process is still running)."
141
echo " (failed to start)."
147
echo " (failed to stop)."
62
echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
153
echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2