[ebc5ae5] | 1 | #!/bin/sh |
---|
| 2 | # Start/stop/restart the BIND name server daemon (named). |
---|
| 3 | |
---|
| 4 | |
---|
| 5 | # Start bind. In the past it was more secure to run BIND as a non-root |
---|
| 6 | # user (for example, with '-u daemon'), but the modern version of BIND |
---|
| 7 | # knows how to use the kernel's capability mechanism to drop all root |
---|
| 8 | # privileges except the ability to bind() to a privileged port and set |
---|
| 9 | # process resource limits, so -u should not be needed. If you wish to |
---|
| 10 | # use it anyway, chown the /var/run/named and /var/named directories to |
---|
| 11 | # the non-root user. The command options can be set like this in |
---|
| 12 | # /etc/default/named : |
---|
| 13 | # NAMED_OPTIONS="-u daemon" |
---|
| 14 | # So you will not have to edit this script. |
---|
| 15 | |
---|
| 16 | # You might also consider running BIND in a "chroot jail", |
---|
| 17 | # a discussion of which may be found in |
---|
| 18 | # /usr/doc/Linux-HOWTOs/Chroot-BIND-HOWTO. |
---|
| 19 | |
---|
| 20 | # One last note: rndc has a lot of other nice features that it is not |
---|
| 21 | # within the scope of this start/stop/restart script to support. |
---|
| 22 | # For more details, see "man rndc" or just type "rndc" to see the options. |
---|
| 23 | |
---|
| 24 | # Load command defaults: |
---|
| 25 | if [ -f /etc/default/named ] ; then . /etc/default/named ; fi |
---|
| 26 | if [ -f /etc/default/rndc ] ; then . /etc/default/rndc ; fi |
---|
| 27 | |
---|
| 28 | # Sanity check. If /usr/sbin/named is missing then it |
---|
| 29 | # doesn't make much sense to try to run this script: |
---|
| 30 | if [ ! -x /usr/sbin/named ]; then |
---|
| 31 | echo "/etc/rc.d/rc.bind: no /usr/sbin/named found (or not executable); cannot start." |
---|
| 32 | exit 1 |
---|
| 33 | fi |
---|
| 34 | |
---|
| 35 | # Start BIND. As many times as you like. ;-) |
---|
| 36 | # Seriously, don't run "rc.bind start" if BIND is already |
---|
| 37 | # running or you'll get more than one copy running. |
---|
| 38 | bind_start() { |
---|
| 39 | if [ -x /usr/sbin/named ]; then |
---|
| 40 | echo "Starting BIND: /usr/sbin/named $NAMED_OPTIONS" |
---|
| 41 | /usr/sbin/named $NAMED_OPTIONS |
---|
| 42 | sleep 1 |
---|
| 43 | fi |
---|
| 44 | if ! ps axc | grep -q named ; then |
---|
| 45 | echo "WARNING: named did not start." |
---|
| 46 | echo "Attempting to start named again: /usr/sbin/named $NAMED_OPTIONS" |
---|
| 47 | /usr/sbin/named $NAMED_OPTIONS |
---|
| 48 | sleep 1 |
---|
| 49 | if ps axc | grep -q named ; then |
---|
| 50 | echo "SUCCESS: named started." |
---|
| 51 | else |
---|
| 52 | echo "FAILED: Sorry, a second attempt to start named has also failed." |
---|
| 53 | echo "There may be a configuration error that needs fixing. Good luck!" |
---|
| 54 | fi |
---|
| 55 | fi |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | # Stop all running copies of BIND (/usr/sbin/named): |
---|
| 59 | bind_stop() { |
---|
| 60 | echo "Stopping BIND: /usr/sbin/rndc $RDNC_OPTIONS stop" |
---|
| 61 | /usr/sbin/rndc $RDNC_OPTIONS stop |
---|
| 62 | # A problem with using "/usr/sbin/rndc stop" is that if you |
---|
| 63 | # managed to get multiple copies of named running it will |
---|
| 64 | # only stop one of them and then can't stop the others even |
---|
| 65 | # if you run it again. So, after doing things the nice way |
---|
| 66 | # we'll do them the old-fashioned way. If you don't like |
---|
| 67 | # it you can comment it out, but unless you have a lot of |
---|
| 68 | # other programs you run called "named" this is unlikely |
---|
| 69 | # to have any ill effects: |
---|
| 70 | sleep 1 |
---|
| 71 | if ps axc | grep -q named ; then |
---|
| 72 | echo "Using "killall named" on additional BIND processes..." |
---|
| 73 | /bin/killall named 2> /dev/null |
---|
| 74 | fi |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | # Reload BIND: |
---|
| 78 | bind_reload() { |
---|
| 79 | /usr/sbin/rndc $RDNC_OPTIONS reload |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | # Restart BIND: |
---|
| 83 | bind_restart() { |
---|
| 84 | bind_stop |
---|
| 85 | bind_start |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | # Get BIND status: |
---|
| 89 | bind_status() { |
---|
| 90 | /usr/sbin/rndc $RDNC_OPTIONS status |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | case "$1" in |
---|
| 94 | 'start') |
---|
| 95 | bind_start |
---|
| 96 | ;; |
---|
| 97 | 'stop') |
---|
| 98 | bind_stop |
---|
| 99 | ;; |
---|
| 100 | 'reload') |
---|
| 101 | bind_reload |
---|
| 102 | ;; |
---|
| 103 | 'restart') |
---|
| 104 | bind_restart |
---|
| 105 | ;; |
---|
| 106 | 'status') |
---|
| 107 | bind_status |
---|
| 108 | ;; |
---|
| 109 | *) |
---|
| 110 | echo "usage $0 start|stop|reload|restart|status" |
---|
| 111 | esac |
---|
| 112 | |
---|