Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Borrowing heavily from the dnsmasq initscript's version of support for |
| 4 | # resolvconf, intended for use in systemd-only configurations. |
| 5 | # |
| 6 | PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin |
| 7 | DAEMON=/usr/sbin/dnsmasq |
| 8 | NAME=dnsmasq |
| 9 | |
| 10 | # Most configuration options in /etc/default/dnsmasq are deprecated |
| 11 | # but still honoured. |
| 12 | if [ -r /etc/default/$NAME ]; then |
| 13 | . /etc/default/$NAME |
| 14 | fi |
| 15 | |
| 16 | start_resolvconf() |
| 17 | { |
| 18 | # If interface "lo" is explicitly disabled in /etc/default/dnsmasq |
| 19 | # Then dnsmasq won't be providing local DNS, so don't add it to |
| 20 | # the resolvconf server set. |
| 21 | for interface in $DNSMASQ_EXCEPT |
| 22 | do |
| 23 | [ $interface = lo ] && return |
| 24 | done |
| 25 | |
| 26 | if [ -x /sbin/resolvconf ] ; then |
| 27 | echo "nameserver 127.0.0.1" | |
| 28 | /sbin/resolvconf -a lo.$NAME |
| 29 | fi |
| 30 | return 0 |
| 31 | } |
| 32 | |
| 33 | stop_resolvconf() |
| 34 | { |
| 35 | if [ -x /sbin/resolvconf ] ; then |
| 36 | /sbin/resolvconf -d lo.$NAME |
| 37 | fi |
| 38 | return 0 |
| 39 | } |
| 40 | |
| 41 | case "$1" in |
| 42 | start) |
| 43 | start_resolvconf |
| 44 | exit 0 |
| 45 | ;; |
| 46 | stop) |
| 47 | stop_resolvconf |
| 48 | exit 0 |
| 49 | ;; |
| 50 | restart) |
| 51 | stop_resolvconf |
| 52 | start_resolvconf |
| 53 | exit 0 |
| 54 | ;; |
| 55 | *) |
| 56 | echo "Usage: /etc/init.d/$NAME {start|stop|restart}" >&2 |
| 57 | exit 3 |
| 58 | ;; |
| 59 | esac |
| 60 | |
| 61 | exit 0 |
| 62 | |