File: pdns-recursor.init

package info (click to toggle)
pdns-recursor 4.1.11-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 6,708 kB
  • sloc: cpp: 54,116; sh: 11,872; makefile: 453; xml: 37
file content (175 lines) | stat: -rw-r--r-- 3,774 bytes parent folder | download | duplicates (3)
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
174
175
#!/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
# Derive the socket-dir setting from /etc/powerdns/recursor.conf
# or fall back to the default /var/run if not specified there.
PIDDIR=$(awk -F= '/^socket-dir=/ {print $2}' /etc/powerdns/recursor.conf)
if [ -z "$PIDDIR" ]; then PIDDIR=/var/run; fi
PIDFILE=$PIDDIR/$NAME.pid

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

# 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=yes || 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
  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)
    if [ "$START" != "yes" ]; then
      echo "Not starting $DESC -- disabled."
      exit 0
    fi
    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)
    if [ "$START" != "yes" ]; then
      $0 stop
      exit 0
    fi
    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