]>
Commit | Line | Data |
---|---|---|
89c4ed63 A |
1 | #!/bin/sh |
2 | # | |
3 | # unbound This shell script takes care of starting and stopping | |
4 | # unbound (DNS server). | |
5 | # | |
6 | # chkconfig: - 14 86 | |
7 | # description: unbound is a Domain Name Server (DNS) \ | |
8 | # that is used to resolve host names to IP addresses. | |
9 | ||
10 | ### BEGIN INIT INFO | |
11 | # Provides: $named unbound | |
12 | # Required-Start: $network $local_fs | |
13 | # Required-Stop: $network $local_fs | |
14 | # Should-Start: $syslog | |
15 | # Should-Stop: $syslog | |
16 | # Short-Description: unbound recursive Domain Name Server. | |
17 | # Description: unbound is a Domain Name Server (DNS) | |
18 | # that is used to resolve host names to IP addresses. | |
19 | ### END INIT INFO | |
20 | ||
21 | # Source function library. | |
22 | . /etc/rc.d/init.d/functions | |
23 | ||
24 | exec="/usr/sbin/unbound" | |
25 | prog="unbound" | |
26 | config="/var/unbound/unbound.conf" | |
27 | pidfile="/var/unbound/unbound.pid" | |
28 | rootdir="/var/unbound" | |
29 | ||
30 | [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog | |
31 | ||
32 | lockfile=/var/lock/subsys/$prog | |
33 | ||
34 | start() { | |
35 | [ -x $exec ] || exit 5 | |
36 | [ -f $config ] || exit 6 | |
37 | echo -n $"Starting $prog: " | |
38 | ||
39 | # setup root jail | |
40 | if [ -s /etc/localtime ]; then | |
41 | [ -d ${rootdir}/etc ] || mkdir -p ${rootdir}/etc ; | |
42 | if [ ! -e ${rootdir}/etc/localtime ] || /usr/bin/cmp -s /etc/localtime ${rootdir}/etc/localtime; then | |
43 | cp -fp /etc/localtime ${rootdir}/etc/localtime | |
44 | fi; | |
45 | fi; | |
46 | if [ -s /etc/resolv.conf ]; then | |
47 | [ -d ${rootdir}/etc ] || mkdir -p ${rootdir}/etc ; | |
48 | if [ ! -e ${rootdir}/etc/resolv.conf ] || /usr/bin/cmp -s /etc/resolv.conf ${rootdir}/etc/resolv.conf; then | |
49 | cp -fp /etc/resolv.conf ${rootdir}/etc/resolv.conf | |
50 | fi; | |
51 | fi; | |
52 | if ! egrep -q '^/[^[:space:]]+[[:space:]]+'${rootdir}'/dev/log' /proc/mounts; then | |
53 | [ -d ${rootdir}/dev ] || mkdir -p ${rootdir}/dev ; | |
54 | [ -e ${rootdir}/dev/log ] || touch ${rootdir}/dev/log | |
55 | mount --bind -n /dev/log ${rootdir}/dev/log >/dev/null 2>&1; | |
56 | fi; | |
57 | if ! egrep -q '^/[^[:space:]]+[[:space:]]+'${rootdir}'/dev/random' /proc/mounts; then | |
58 | [ -d ${rootdir}/dev ] || mkdir -p ${rootdir}/dev ; | |
59 | [ -e ${rootdir}/dev/random ] || touch ${rootdir}/dev/random | |
60 | mount --bind -n /dev/random ${rootdir}/dev/random >/dev/null 2>&1; | |
61 | fi; | |
62 | ||
63 | # if not running, start it up here | |
64 | daemon $exec | |
65 | retval=$? | |
66 | echo | |
67 | [ $retval -eq 0 ] && touch $lockfile | |
68 | return $retval | |
69 | } | |
70 | ||
71 | stop() { | |
72 | echo -n $"Stopping $prog: " | |
73 | # stop it here, often "killproc $prog" | |
74 | killproc -p $pidfile $prog | |
75 | retval=$? | |
76 | echo | |
77 | [ $retval -eq 0 ] && rm -f $lockfile | |
78 | if egrep -q '^/[^[:space:]]+[[:space:]]+'${rootdir}'/dev/log' /proc/mounts; then | |
79 | umount ${rootdir}/dev/log >/dev/null 2>&1 | |
80 | fi; | |
81 | if egrep -q '^/[^[:space:]]+[[:space:]]+'${rootdir}'/dev/random' /proc/mounts; then | |
82 | umount ${rootdir}/dev/random >/dev/null 2>&1 | |
83 | fi; | |
84 | return $retval | |
85 | } | |
86 | ||
87 | restart() { | |
88 | stop | |
89 | start | |
90 | } | |
91 | ||
92 | reload() { | |
93 | kill -HUP `cat $pidfile` | |
94 | } | |
95 | ||
96 | force_reload() { | |
97 | restart | |
98 | } | |
99 | ||
100 | rh_status() { | |
101 | # run checks to determine if the service is running or use generic status | |
102 | status -p $pidfile $prog | |
103 | } | |
104 | ||
105 | rh_status_q() { | |
106 | rh_status -p $pidfile >/dev/null 2>&1 | |
107 | } | |
108 | ||
109 | case "$1" in | |
110 | start) | |
111 | rh_status_q && exit 0 | |
112 | $1 | |
113 | ;; | |
114 | stop) | |
115 | rh_status_q || exit 0 | |
116 | $1 | |
117 | ;; | |
118 | restart) | |
119 | $1 | |
120 | ;; | |
121 | reload) | |
122 | rh_status_q || exit 7 | |
123 | $1 | |
124 | ;; | |
125 | force-reload) | |
126 | force_reload | |
127 | ;; | |
128 | status) | |
129 | rh_status | |
130 | ;; | |
131 | condrestart|try-restart) | |
132 | rh_status_q || exit 0 | |
133 | restart | |
134 | ;; | |
135 | *) | |
136 | echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" | |
137 | exit 2 | |
138 | esac | |
139 | exit $? |