]> Pileus Git - ~andy/sunrise/blob - net-dns/nsd/files/nsd.initd
net-dns/nsd: correct $extra_commands usage
[~andy/sunrise] / net-dns / nsd / files / nsd.initd
1 #!/sbin/runscript 
2 # Copyright 1999-2012 Gentoo Foundation 
3 # Distributed under the terms of the GNU General Public License v2 
4 # $Header: $ 
5 #
6 extra_commands="rebuild"
7 extra_started_commands="reload"
8 description="NSD is an authoritative only, high performance, open source name server"
9 description_reload="Rebuild zone database and reload it"
10
11 config_file=${config_file:-/etc/nsd/nsd.conf}
12 my_nsdc="/usr/sbin/nsdc"
13 my_nsd_checkconf="/usr/sbin/nsd-checkconf"
14
15 depend() { 
16         need net 
17         use logger 
18         provide auth-dns
19
20
21 _checkconf() {
22         if ! test -e "${config_file}"; then
23                 eerror "You need to create an appropriate config file."
24                 eerror "An example can be found in /etc/nsd/nsd.conf.sample"
25                 return 1
26         fi
27
28         if ! ${my_nsd_checkconf} "${config_file}"; then
29                 eerror "You have errors in your configfile (${config_file})"
30                 return 1
31         fi
32         return 0
33 }
34
35 _checkdb() {
36         local database=$(${my_nsd_checkconf} -o database ${config_file})
37         if ! test -f $database; then
38                 eerror "You have no database file in ${database}, will try to rebuild"
39                 _rebuild
40         fi
41         return 0
42 }
43
44 _patch() {
45         local difffile=$(${my_nsd_checkconf} -o difffile ${config_file})
46         if test -s ${difffile}; then
47                 ebegin "Patching NSD zone files"
48                 ${my_nsdc} patch > /dev/null
49                 eend $?
50         fi
51 }
52
53 rebuild() {
54         ebegin "Rebuilding NSD zone database"
55         if ! ${my_nsdc} rebuild > /dev/null; then
56                 eerror "There was an error rebuilding the database. Please review your zone files."
57                 return 1
58         fi
59         eend $?
60 }
61
62 start() { 
63         ebegin "Starting NSD"
64         _checkconf || return 1
65         _checkdb || rebuild || return 1
66         ${my_nsdc} start
67         ${my_nsdc} running
68         eend $? 
69 }
70
71 stop() { 
72         ebegin "Stopping NSD"
73         _patch
74         ${my_nsdc} stop
75         eend $? 
76
77
78 reload() {
79         _checkconf || return 1
80         rebuild || return 1
81         ebegin "Reloading NSD zone database"
82         ${my_nsdc} reload
83         eend $? 
84 }