~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to vivid/etc/init.d/bind9

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh -e
 
2
 
 
3
### BEGIN INIT INFO
 
4
# Provides:          bind9
 
5
# Required-Start:    $remote_fs
 
6
# Required-Stop:     $remote_fs
 
7
# Should-Start:      $network $syslog
 
8
# Should-Stop:       $network $syslog
 
9
# Default-Start:     2 3 4 5
 
10
# Default-Stop:      0 1 6
 
11
# Short-Description: Start and stop bind9
 
12
# Description:       bind9 is a Domain Name Server (DNS)
 
13
#        which translates ip addresses to and from internet names
 
14
### END INIT INFO
 
15
 
 
16
PATH=/sbin:/bin:/usr/sbin:/usr/bin
 
17
 
 
18
# for a chrooted server: "-u bind -t /var/lib/named"
 
19
# Don't modify this line, change or create /etc/default/bind9.
 
20
OPTIONS=""
 
21
RESOLVCONF=no
 
22
 
 
23
test -f /etc/default/bind9 && . /etc/default/bind9
 
24
 
 
25
test -x /usr/sbin/rndc || exit 0
 
26
 
 
27
. /lib/lsb/init-functions
 
28
PIDFILE=/var/run/named/named.pid
 
29
 
 
30
check_network() {
 
31
    if [ -x /usr/bin/uname ] && [ "X$(/usr/bin/uname -o)" = XSolaris ]; then
 
32
        IFCONFIG_OPTS="-au"
 
33
    else
 
34
        IFCONFIG_OPTS=""
 
35
    fi
 
36
    if [ -z "$(/sbin/ifconfig $IFCONFIG_OPTS)" ]; then
 
37
       #log_action_msg "No networks configured."
 
38
       return 1
 
39
    fi
 
40
    return 0
 
41
}
 
42
 
 
43
case "$1" in
 
44
    start)
 
45
        log_daemon_msg "Starting domain name service..." "bind9"
 
46
 
 
47
        modprobe capability >/dev/null 2>&1 || true
 
48
 
 
49
        # dirs under /var/run can go away on reboots.
 
50
        mkdir -p /var/run/named
 
51
        chmod 775 /var/run/named
 
52
        chown root:bind /var/run/named >/dev/null 2>&1 || true
 
53
 
 
54
        if [ ! -x /usr/sbin/named ]; then
 
55
            log_action_msg "named binary missing - not starting"
 
56
            log_end_msg 1
 
57
        fi
 
58
 
 
59
        if ! check_network; then
 
60
            log_action_msg "no networks configured"
 
61
            log_end_msg 1
 
62
        fi
 
63
 
 
64
        if start-stop-daemon --start --oknodo --quiet --exec /usr/sbin/named \
 
65
                --pidfile ${PIDFILE} -- $OPTIONS; then
 
66
            if [ "X$RESOLVCONF" != "Xno" ] && [ -x /sbin/resolvconf ] ; then
 
67
                echo "nameserver 127.0.0.1" | /sbin/resolvconf -a lo.named
 
68
            fi
 
69
            log_end_msg 0
 
70
        else
 
71
            log_end_msg 1
 
72
        fi
 
73
    ;;
 
74
 
 
75
    stop)
 
76
        log_daemon_msg "Stopping domain name service..." "bind9"
 
77
        if ! check_network; then
 
78
            log_action_msg "no networks configured"
 
79
            log_end_msg 1
 
80
        fi
 
81
 
 
82
        if [ "X$RESOLVCONF" != "Xno" ] && [ -x /sbin/resolvconf ] ; then
 
83
            /sbin/resolvconf -d lo.named
 
84
        fi
 
85
        pid=$(/usr/sbin/rndc stop -p | awk '/^pid:/ {print $2}') || true
 
86
        if [ -z "$pid" ]; then          # no pid found, so either not running, or error
 
87
            pid=$(pgrep -f ^/usr/sbin/named) || true
 
88
            start-stop-daemon --stop --oknodo --quiet --exec /usr/sbin/named \
 
89
                    --pidfile ${PIDFILE} -- $OPTIONS
 
90
        fi
 
91
        if [ -n "$pid" ]; then
 
92
            sig=0
 
93
            n=1
 
94
            while kill -$sig $pid 2>/dev/null; do
 
95
                if [ $n -eq 1 ]; then
 
96
                    echo "waiting for pid $pid to die"
 
97
                fi
 
98
                if [ $n -eq 11 ]; then
 
99
                    echo "giving up on pid $pid with kill -0; trying -9"
 
100
                    sig=9
 
101
                fi
 
102
                if [ $n -gt 20 ]; then
 
103
                    echo "giving up on pid $pid"
 
104
                    break
 
105
                fi
 
106
                n=$(($n+1))
 
107
                sleep 1
 
108
            done
 
109
        fi
 
110
        log_end_msg 0
 
111
    ;;
 
112
 
 
113
    reload|force-reload)
 
114
        log_daemon_msg "Reloading domain name service..." "bind9"
 
115
        if ! check_network; then
 
116
            log_action_msg "no networks configured"
 
117
            log_end_msg 1
 
118
        fi
 
119
 
 
120
        /usr/sbin/rndc reload >/dev/null && log_end_msg 0 || log_end_msg 1
 
121
    ;;
 
122
 
 
123
    restart)
 
124
        if ! check_network; then
 
125
            log_action_msg "no networks configured"
 
126
            exit 1
 
127
        fi
 
128
 
 
129
        $0 stop
 
130
        $0 start
 
131
    ;;
 
132
    
 
133
    status)
 
134
        ret=0
 
135
        status_of_proc -p ${PIDFILE} /usr/sbin/named bind9 2>/dev/null || ret=$?
 
136
        exit $ret
 
137
        ;;
 
138
 
 
139
    *)
 
140
        log_action_msg "Usage: /etc/init.d/bind9 {start|stop|reload|restart|force-reload|status}"
 
141
        exit 1
 
142
    ;;
 
143
esac
 
144
 
 
145
exit 0