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