]> git.ipfire.org Git - thirdparty/pdns.git/blob - builder-support/debian/recursor/debian-jessie/pdns-recursor.init
63390cf4489fb0676a70485a68e2063fce0c10f8
[thirdparty/pdns.git] / builder-support / debian / recursor / debian-jessie / pdns-recursor.init
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 # Load lsb stuff for systemd redirection (if available).
22 if [ -e /lib/lsb/init-functions ]; then
23 . /lib/lsb/init-functions
24 fi
25
26 PATH=/sbin:/bin:/usr/sbin:/usr/bin
27 DESC="PowerDNS Recursor"
28 NAME=pdns_recursor
29 DAEMON=/usr/sbin/$NAME
30 # Derive the socket-dir setting from /etc/powerdns/recursor.conf
31 # or fall back to the default /var/run if not specified there.
32 PIDDIR=$(awk -F= '/^socket-dir=/ {print $2}' /etc/powerdns/recursor.conf)
33 if [ -z "$PIDDIR" ]; then PIDDIR=/var/run; fi
34 PIDFILE=$PIDDIR/$NAME.pid
35
36 # Gracefully exit if the package has been removed.
37 test -x $DAEMON || exit 0
38
39 # Read config file if it is present.
40 if [ -r /etc/default/pdns-recursor ]; then
41 . /etc/default/pdns-recursor
42 fi
43
44 start() {
45 # Return
46 # 0 if daemon has been started / was already running
47 # >0 if daemon could not be started
48 start-stop-daemon --start --oknodo --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null || return 0
49 start-stop-daemon --start --oknodo --quiet --pidfile $PIDFILE --exec $DAEMON -- --daemon=yes || return 2
50 }
51
52 start_resolvconf() {
53 if [ "X$RESOLVCONF" = "Xyes" ] && [ -x /sbin/resolvconf ]; then
54 echo "nameserver 127.0.0.1" | /sbin/resolvconf -a lo.pdns-recursor
55 fi
56 return 0
57 }
58
59 stop() {
60 # Return
61 # 0 if daemon has been stopped
62 # 1 if daemon was already stopped
63 # 2 if daemon could not be stopped
64 # other if a failure occured
65 start-stop-daemon --stop --quiet --pidfile $PIDFILE --name $NAME
66 RETVAL="$?"
67 [ "$RETVAL" = 2 ] && return 2
68 rm -f $PIDFILE
69 return "$RETVAL"
70 }
71
72 stop_resolvconf() {
73 if [ "X$RESOLVCONF" = "Xyes" ] && [ -x /sbin/resolvconf ]; then
74 /sbin/resolvconf -d lo.pdns-recursor
75 fi
76 return 0
77 }
78
79 isrunning()
80 {
81 /usr/bin/rec_control ping > /dev/null
82 return $?
83 }
84
85 case "$1" in
86 start)
87 if [ "$START" != "yes" ]; then
88 echo "Not starting $DESC -- disabled."
89 exit 0
90 fi
91 echo -n "Starting $DESC: $NAME ..."
92 start
93 case "$?" in
94 0)
95 start_resolvconf
96 echo done
97 break
98 ;;
99 1)
100 echo "already running"
101 break
102 ;;
103 *)
104 echo "failed"
105 exit 1
106 ;;
107 esac
108 ;;
109 stop)
110 stop_resolvconf
111 echo -n "Stopping $DESC: $NAME ..."
112 stop
113 case "$?" in
114 0)
115 echo done
116 break
117 ;;
118 1)
119 echo "not running"
120 break
121 ;;
122 *)
123 echo "failed"
124 exit 1
125 ;;
126 esac
127 ;;
128 restart|force-reload)
129 if [ "$START" != "yes" ]; then
130 $0 stop
131 exit 0
132 fi
133 echo -n "Restarting $DESC ..."
134 stop
135 case "$?" in
136 0|1)
137 start
138 case "$?" in
139 0)
140 echo done
141 exit 0
142 ;;
143 1)
144 echo "failed -- old process still running"
145 exit 1
146 ;;
147 *)
148 echo "failed to start"
149 exit 1
150 ;;
151 esac
152 ;;
153 *)
154 echo "failed to stop"
155 exit 1
156 ;;
157 esac
158 ;;
159 status)
160 if isrunning; then
161 echo "$NAME is running"
162 exit 0
163 else
164 echo "$NAME is not running or not responding"
165 exit 3
166 fi
167 ;;
168 *)
169 echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
170 exit 3
171 ;;
172 esac
173
174 exit 0
175