~cyphermox/ubuntu/precise/dnsmasq/dbus

« back to all changes in this revision

Viewing changes to debian/init

  • Committer: Bazaar Package Importer
  • Author(s): Simon Kelley
  • Date: 2005-05-04 13:25:23 UTC
  • mfrom: (0.2.1 upstream) (1.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050504132523-29x9nzdnkypp62nc
Tags: 2.22-2
Make the resolv.conf polling code resistant to 
backwards-moving system clocks. (closes: #306117) (closes: #300694)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /bin/sh
 
1
#!/bin/sh
2
2
 
3
# dnsmasq
 
4
 
 
5
set +e   # Don't exit on error status
3
6
 
4
7
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
5
8
DAEMON=/usr/sbin/dnsmasq
6
 
NAME="dnsmasq"
7
 
DESC="caching dns forwarder"
8
 
 
9
 
# configuration options are now in /etc/default/dnsmasq
10
 
 
11
 
if [ -f /etc/default/$NAME ]; then
12
 
  . /etc/default/$NAME
13
 
fi
14
 
 
15
 
test -f $DAEMON || exit 0
16
 
 
17
 
set -e
 
9
NAME=dnsmasq
 
10
DESC="DNS forwarder and DHCP server"
 
11
 
 
12
# Most configuration options in /etc/default/dnsmasq are deprecated
 
13
# but still honoured.
 
14
 
 
15
if [ -r /etc/default/$NAME ]; then
 
16
        . /etc/default/$NAME
 
17
fi
 
18
 
 
19
test -x $DAEMON || exit 0
 
20
 
 
21
# RESOLV_CONF:
 
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
 
24
# the default.
 
25
#
 
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 .
 
29
 
 
30
if [ ! "$RESOLV_CONF" ] &&
 
31
   [ -x /sbin/resolvconf ]
 
32
then
 
33
        RESOLV_CONF=/var/run/dnsmasq/resolv.conf
 
34
fi
 
35
 
 
36
for INTERFACE in $DNSMASQ_INTERFACE; do
 
37
        DNSMASQ_INTERFACES="$DNSMASQ_INTERFACES -i $INTERFACE"
 
38
done
 
39
 
 
40
start()
 
41
{
 
42
        # Return
 
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} \
 
57
                || return 2
 
58
}
 
59
 
 
60
start_resolvconf()
 
61
{
 
62
        if [ -x /sbin/resolvconf ] ; then
 
63
                echo "nameserver 127.0.0.1" | /sbin/resolvconf -a lo.$NAME
 
64
        fi
 
65
        return 0
 
66
}
 
67
 
 
68
stop()
 
69
{
 
70
        # Return
 
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
 
76
        RETVAL="$?"
 
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
 
82
        return "$RETVAL"
 
83
}
 
84
 
 
85
stop_resolvconf()
 
86
{
 
87
        if [ -x /sbin/resolvconf ] ; then
 
88
                /sbin/resolvconf -d lo.$NAME
 
89
        fi
 
90
        return 0
 
91
}
18
92
 
19
93
case "$1" in
20
94
  start)
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}
31
 
        echo "$NAME."
 
95
        echo -n "Starting $DESC: $NAME"
 
96
        start
 
97
        case "$?" in
 
98
                0)
 
99
                        echo "."
 
100
                        start_resolvconf
 
101
                        exit 0
 
102
                        ;;
 
103
                1)
 
104
                        echo " (already running)."
 
105
                        exit 0
 
106
                        ;;
 
107
                *)
 
108
                        echo " (failed)."
 
109
                        exit 1
 
110
                        ;;
 
111
        esac
32
112
        ;;
33
113
  stop)
34
 
        echo -n "Stopping $DESC: "
35
 
        start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
36
 
                --exec $DAEMON
37
 
        echo "$NAME."
 
114
        stop_resolvconf
 
115
        echo -n "Stopping $DESC: $NAME"
 
116
        stop
 
117
        case "$?" in
 
118
                0) echo "." ; exit 0 ;;
 
119
                1) echo " (not running)." ; exit 0 ;;
 
120
                *) echo " (failed)." ; exit 1 ;;
 
121
        esac
38
122
        ;;
39
 
  reload|force-reload)
40
 
        echo "Reloading $DESC configuration files."
41
 
        start-stop-daemon --stop --signal 1 --quiet --pidfile \
42
 
               /var/run/$NAME.pid --exec $DAEMON
43
 
        ;;
44
 
  restart)
45
 
        echo -n "Restarting $DESC: "
46
 
        start-stop-daemon --stop --quiet --pidfile \
47
 
                /var/run/$NAME.pid --exec $DAEMON
48
 
        sleep 1
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}
58
 
        echo "$NAME."
 
123
  restart|force-reload)
 
124
        stop_resolvconf
 
125
        echo -n "Restarting $DESC: $NAME"
 
126
        stop
 
127
        case "$?" in
 
128
                0|1)
 
129
                        start
 
130
                        case "$?" in
 
131
                                0)
 
132
                                        echo "."
 
133
                                        start_resolvconf
 
134
                                        exit 0
 
135
                                        ;;
 
136
                                1)
 
137
                                        echo " (failed -- old process is still running)."
 
138
                                        exit 1
 
139
                                        ;;
 
140
                                *)
 
141
                                        echo " (failed to start)."
 
142
                                        exit 1
 
143
                                        ;;
 
144
                        esac
 
145
                        ;;
 
146
                *)
 
147
                        echo " (failed to stop)."
 
148
                        exit 1
 
149
                        ;;
 
150
        esac
59
151
        ;;
60
152
  *)
61
 
        N=/etc/init.d/$NAME
62
 
        echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
63
 
        exit 1
 
153
        echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2
 
154
        exit 3
64
155
        ;;
65
156
esac
66
157
 
67
158
exit 0
 
159