]>
Commit | Line | Data |
---|---|---|
8cc3b20e PL |
1 | #!/bin/sh |
2 | ### BEGIN INIT INFO | |
3 | # Provides: pdns-recursor | |
4 | # Required-Start: $network $remote_fs $syslog | |
5 | # Required-Stop: $network $remote_fs $syslog | |
6 | # Default-Start: 2 3 4 5 | |
7 | # Default-Stop: 0 1 6 | |
8 | # Short-Description: PowerDNS Recursor - Recursive DNS Server | |
9 | # Description: PowerDNS Recursor - Recursive DNS Server | |
10 | ### END INIT INFO | |
11 | ||
12 | # | |
13 | # Authors: Matthijs Möhlmann <matthijs@cacholong.nl> | |
14 | # Christoph Haas <haas@debian.org> | |
15 | # | |
16 | # Thanks to: | |
17 | # Thomas Hood <jdthood@aglu.demon.nl> | |
18 | # | |
19 | # initscript for PowerDNS recursor | |
20 | ||
21 | . /lib/lsb/init-functions | |
22 | ||
23 | PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
24 | DESC="PowerDNS recursor" | |
25 | NAME=pdns_recursor | |
26 | DAEMON=/usr/sbin/$NAME | |
27 | # Derive the socket-dir setting from /etc/powerdns/recursor.conf | |
28 | # or fall back to the default /var/run if not specified there. | |
29 | PIDDIR=$(awk -F= '/^socket-dir=/ {print $2}' /etc/powerdns/recursor.conf) | |
30 | if [ -z "$PIDDIR" ]; then PIDDIR=/var/run; fi | |
3348eb47 | 31 | mkdir -p "$PIDDIR" |
8cc3b20e PL |
32 | PIDFILE=$PIDDIR/$NAME.pid |
33 | ||
34 | # Gracefully exit if the package has been removed. | |
35 | test -x $DAEMON || exit 0 | |
36 | ||
37 | # Read config file if it is present. | |
38 | if [ -r /etc/default/pdns-recursor ]; then | |
39 | . /etc/default/pdns-recursor | |
40 | fi | |
41 | ||
42 | start() { | |
43 | # Return | |
44 | # 0 if daemon has been started / was already running | |
45 | # >0 if daemon could not be started | |
46 | start-stop-daemon --start --oknodo --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null || return 0 | |
d3f809bf | 47 | start-stop-daemon --start --oknodo --quiet --pidfile $PIDFILE --exec $DAEMON -- --daemon=yes || return 2 |
8cc3b20e PL |
48 | } |
49 | ||
50 | start_resolvconf() { | |
51 | if [ "X$RESOLVCONF" = "Xyes" ] && [ -x /sbin/resolvconf ]; then | |
52 | echo "nameserver 127.0.0.1" | /sbin/resolvconf -a lo.pdns-recursor | |
53 | fi | |
54 | return 0 | |
55 | } | |
56 | ||
57 | stop() { | |
58 | # Return | |
59 | # 0 if daemon has been stopped | |
60 | # 1 if daemon was already stopped | |
61 | # 2 if daemon could not be stopped | |
62 | # other if a failure occured | |
63 | start-stop-daemon --stop --quiet --retry=HUP/30/TERM/5/KILL/5 --pidfile $PIDFILE --name $NAME | |
64 | RETVAL="$?" | |
65 | [ "$RETVAL" = 2 ] && return 2 | |
66 | rm -f $PIDFILE | |
67 | return "$RETVAL" | |
68 | } | |
69 | ||
70 | stop_resolvconf() { | |
71 | if [ "X$RESOLVCONF" = "Xyes" ] && [ -x /sbin/resolvconf ]; then | |
72 | /sbin/resolvconf -d lo.pdns-recursor | |
73 | fi | |
74 | return 0 | |
75 | } | |
76 | ||
77 | case "$1" in | |
78 | start) | |
79 | if [ "$START" != "yes" ]; then | |
80 | log_begin_msg "Not starting $DESC -- disabled." | |
81 | log_end_msg 0 | |
82 | exit 0 | |
83 | fi | |
84 | log_daemon_msg "Starting $DESC" "pdns-recursor" | |
85 | start | |
86 | case "$?" in | |
87 | 0) | |
88 | start_resolvconf | |
89 | break | |
90 | ;; | |
91 | 1) | |
92 | log_progress_msg "(already running)" | |
93 | break | |
94 | ;; | |
95 | *) | |
96 | log_progress_msg " (failed)." | |
97 | log_end_msg 1 | |
98 | exit 1 | |
99 | ;; | |
100 | esac | |
101 | log_end_msg 0 | |
102 | ;; | |
103 | stop) | |
104 | stop_resolvconf | |
105 | log_daemon_msg "Stopping $DESC" "pdns-recursor" | |
106 | stop | |
107 | case "$?" in | |
108 | 0) | |
109 | break | |
110 | ;; | |
111 | 1) | |
112 | log_progress_msg "(not running)" | |
113 | break | |
114 | ;; | |
115 | *) | |
116 | log_progress_msg "(failed)" | |
117 | log_end_msg 1 | |
118 | exit 1 | |
119 | ;; | |
120 | esac | |
121 | log_end_msg 0 | |
122 | ;; | |
123 | restart|force-reload) | |
124 | if [ "$START" != "yes" ]; then | |
125 | $0 stop | |
126 | exit 0 | |
127 | fi | |
128 | log_daemon_msg "Restarting $DESC" "pdns-recursor" | |
129 | stop | |
130 | case "$?" in | |
131 | 0|1) | |
132 | start | |
133 | case "$?" in | |
134 | 0) | |
135 | log_end_msg 0 | |
136 | exit 0 | |
137 | ;; | |
138 | 1) | |
139 | log_progress_msg "(failed -- old process still running)" | |
140 | log_end_msg 1 | |
141 | exit 1 | |
142 | ;; | |
143 | *) | |
144 | log_progress_msg "(failed to start)" | |
145 | log_end_msg 1 | |
146 | exit 1 | |
147 | ;; | |
148 | esac | |
149 | ;; | |
150 | *) | |
151 | log_progress_msg "(failed to stop)" | |
152 | log_end_msg 1 | |
153 | exit 1 | |
154 | ;; | |
155 | esac | |
156 | ;; | |
157 | force-stop) | |
158 | killall -v -9 pdns_recursor | |
159 | echo "killed" | |
160 | ;; | |
161 | status) | |
162 | status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $? | |
163 | ;; | |
164 | *) | |
165 | echo "Usage: $0 {start|stop|restart|force-reload|force-stop|status}" >&2 | |
166 | exit 3 | |
167 | ;; | |
168 | esac | |
169 | ||
170 | exit 0 | |
171 |