]> Pileus Git - ~andy/sunrise/blobdiff - net-dns/nsd/files/nsd.initd
media-video/ucview: fix metadata.xml
[~andy/sunrise] / net-dns / nsd / files / nsd.initd
index a2ad26a73c57f1398f6aa6afa656d9f32954068d..1325420aa7dc82871279ffa8380c2952cdf288a7 100644 (file)
@@ -1,12 +1,12 @@
 #!/sbin/runscript 
-# Copyright 1999-2009 Gentoo Foundation 
+# Copyright 1999-2012 Gentoo Foundation 
 # Distributed under the terms of the GNU General Public License v2 
 # $Header: $ 
 #
-opts="${opts} reload"
+extra_commands="rebuild"
+extra_started_commands="reload"
 description="NSD is an authoritative only, high performance, open source name server"
-description_start="Start the server"
-description_stop="Stop the server"
+description_rebuild="Rebuild zone database"
 description_reload="Rebuild zone database and reload it"
 
 config_file=${config_file:-/etc/nsd/nsd.conf}
@@ -20,7 +20,7 @@ depend() {
 } 
 
 _checkconf() {
-       if [ ! -e "${config_file}" ]; then
+       if ! test -e "${config_file}"; then
                eerror "You need to create an appropriate config file."
                eerror "An example can be found in /etc/nsd/nsd.conf.sample"
                return 1
@@ -33,8 +33,17 @@ _checkconf() {
        return 0
 }
 
+_checkdb() {
+       local database=$(${my_nsd_checkconf} -o database ${config_file})
+       if ! test -f $database; then
+               eerror "You have no database file in ${database}, will try to rebuild"
+               rebuild
+       fi
+       return 0
+}
+
 _patch() {
-       local difffile=`${my_nsd_checkconf} -o difffile ${config_file}`
+       local difffile=$(${my_nsd_checkconf} -o difffile ${config_file})
        if test -s ${difffile}; then
                ebegin "Patching NSD zone files"
                ${my_nsdc} patch > /dev/null
@@ -42,17 +51,23 @@ _patch() {
        fi
 }
 
-_rebuild() {
+rebuild() {
+       ebegin "Rebuilding NSD zone database"
        if ! ${my_nsdc} rebuild > /dev/null; then
                eerror "There was an error rebuilding the database. Please review your zone files."
                return 1
        fi
-       return 0
+       eend $?
 }
 
 start() { 
        ebegin "Starting NSD"
+
+       local pidfile=$(${my_nsd_checkconf} -o pidfile ${config_file})
+       checkpath -d -o nsd:nsd $(dirname ${pidfile})
+
        _checkconf || return 1
+       _checkdb || return 1
        ${my_nsdc} start
        ${my_nsdc} running
        eend $? 
@@ -66,9 +81,9 @@ stop() {
 } 
 
 reload() {
-       ebegin "Rebuilding and reloading NSD zone database"
        _checkconf || return 1
-       _rebuild || return 1
+       rebuild || return 1
+       ebegin "Reloading NSD zone database"
        ${my_nsdc} reload
        eend $? 
 }