]> Pileus Git - ~andy/sunrise/blob - net-dns/nsd/files/nsd.initd
media-video/ucview: fix metadata.xml
[~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_rebuild="Rebuild zone database"
10 description_reload="Rebuild zone database and reload it"
11
12 config_file=${config_file:-/etc/nsd/nsd.conf}
13 my_nsdc="/usr/sbin/nsdc"
14 my_nsd_checkconf="/usr/sbin/nsd-checkconf"
15
16 depend() { 
17         need net 
18         use logger 
19         provide auth-dns
20
21
22 _checkconf() {
23         if ! test -e "${config_file}"; then
24                 eerror "You need to create an appropriate config file."
25                 eerror "An example can be found in /etc/nsd/nsd.conf.sample"
26                 return 1
27         fi
28
29         if ! ${my_nsd_checkconf} "${config_file}"; then
30                 eerror "You have errors in your configfile (${config_file})"
31                 return 1
32         fi
33         return 0
34 }
35
36 _checkdb() {
37         local database=$(${my_nsd_checkconf} -o database ${config_file})
38         if ! test -f $database; then
39                 eerror "You have no database file in ${database}, will try to rebuild"
40                 rebuild
41         fi
42         return 0
43 }
44
45 _patch() {
46         local difffile=$(${my_nsd_checkconf} -o difffile ${config_file})
47         if test -s ${difffile}; then
48                 ebegin "Patching NSD zone files"
49                 ${my_nsdc} patch > /dev/null
50                 eend $?
51         fi
52 }
53
54 rebuild() {
55         ebegin "Rebuilding NSD zone database"
56         if ! ${my_nsdc} rebuild > /dev/null; then
57                 eerror "There was an error rebuilding the database. Please review your zone files."
58                 return 1
59         fi
60         eend $?
61 }
62
63 start() { 
64         ebegin "Starting NSD"
65
66         local pidfile=$(${my_nsd_checkconf} -o pidfile ${config_file})
67         checkpath -d -o nsd:nsd $(dirname ${pidfile})
68
69         _checkconf || return 1
70         _checkdb || return 1
71         ${my_nsdc} start
72         ${my_nsdc} running
73         eend $? 
74 }
75
76 stop() { 
77         ebegin "Stopping NSD"
78         _patch
79         ${my_nsdc} stop
80         eend $? 
81
82
83 reload() {
84         _checkconf || return 1
85         rebuild || return 1
86         ebegin "Reloading NSD zone database"
87         ${my_nsdc} reload
88         eend $? 
89 }