]> git.pld-linux.org Git - packages/unbound.git/blob - unbound.init
- nfy
[packages/unbound.git] / unbound.init
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 ### END INIT INFO
11
12 # Source function library.
13 . /etc/rc.d/init.d/functions
14
15 pidfile="/var/unbound/unbound.pid"
16
17 [ -e /etc/sysconfig/unbound ] && . /etc/sysconfig/unbound
18
19 lockfile=/var/lock/subsys/unbound
20
21 start() {
22     [ -x /usr/sbin/unbound ] || exit 5
23     [ -f /etc/unbound/unbound.conf ] || exit 6
24     echo -n $"Starting unbound: "
25
26     # setup root jail
27     if [ -s /etc/localtime ]; then 
28         [ -d /var/lib/unbound/etc ] || mkdir -p /var/lib/unbound/etc ;
29         if [ ! -e /var/lib/unbound/etc/localtime ] || /usr/bin/cmp -s /etc/localtime /var/lib/unbound/etc/localtime; then
30             cp -fp /etc/localtime /var/lib/unbound/etc/localtime
31         fi;
32     fi;
33     if [ -s /etc/resolv.conf ]; then
34         [ -d /var/lib/unbound/etc ] || mkdir -p /var/lib/unbound/etc ;
35         if [ ! -e /var/lib/unbound/etc/resolv.conf ] || /usr/bin/cmp -s /etc/resolv.conf /var/lib/unbound/etc/resolv.conf; then
36             cp -fp /etc/resolv.conf /var/lib/unbound/etc/resolv.conf
37         fi;
38     fi;
39     if ! egrep -q '^/[^[:space:]]+[[:space:]]+'/var/lib/unbound'/dev/log' /proc/mounts; then
40         [ -d /var/lib/unbound/dev ] || mkdir -p /var/lib/unbound/dev ;
41         [ -e /var/lib/unbound/dev/log ] || touch /var/lib/unbound/dev/log
42         mount --bind -n /dev/log /var/lib/unbound/dev/log >/dev/null 2>&1;
43     fi;
44     if ! egrep -q '^/[^[:space:]]+[[:space:]]+'/var/lib/unbound'/dev/random' /proc/mounts; then
45         [ -d /var/lib/unbound/dev ] || mkdir -p /var/lib/unbound/dev ;
46         [ -e /var/lib/unbound/dev/random ] || touch /var/lib/unbound/dev/random
47         mount --bind -n /dev/random /var/lib/unbound/dev/random >/dev/null 2>&1;
48     fi;
49
50     # if not running, start it up here
51     daemon /usr/sbin/unbound
52     retval=$?
53     echo
54     [ $retval -eq 0 ] && touch $lockfile
55     return $retval
56 }
57
58 stop() {
59     echo -n $"Stopping unbound: "
60     # stop it here, often "killproc unbound"
61     killproc -p $pidfile unbound
62     retval=$?
63     echo
64     [ $retval -eq 0 ] && rm -f $lockfile
65     if egrep -q '^/[^[:space:]]+[[:space:]]+'/var/lib/unbound'/dev/log' /proc/mounts; then
66         umount /var/lib/unbound/dev/log >/dev/null 2>&1
67     fi;
68     if egrep -q '^/[^[:space:]]+[[:space:]]+'/var/lib/unbound'/dev/random' /proc/mounts; then
69         umount /var/lib/unbound/dev/random >/dev/null 2>&1
70     fi;
71     return $retval
72 }
73
74 restart() {
75     stop
76     start
77 }
78
79 reload() {
80     kill -HUP `cat $pidfile`
81 }
82
83 force_reload() {
84     restart
85 }
86
87 rh_status() {
88     # run checks to determine if the service is running or use generic status
89     status -p $pidfile unbound
90 }
91
92 rh_status_q() {
93     rh_status -p $pidfile >/dev/null 2>&1
94 }
95
96 case "$1" in
97     start)
98         rh_status_q && exit 0
99         $1
100         ;;
101     stop)
102         rh_status_q || exit 0
103         $1
104         ;;
105     restart)
106         $1
107         ;;
108     reload)
109         rh_status_q || exit 7
110         $1
111         ;;
112     force-reload)
113         force_reload
114         ;;
115     status)
116         rh_status
117         ;;
118     condrestart|try-restart)
119         rh_status_q || exit 0
120         restart
121         ;;
122     *)
123         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
124         exit 2
125 esac
126 exit $?
This page took 0.082527 seconds and 4 git commands to generate.