[packages/pdns] initscript: move to functions

glen glen at pld-linux.org
Wed Oct 28 11:38:07 CET 2015


commit 5311dff8cce12b84bd681297669a9941ca271d8f
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Wed Oct 28 12:37:53 2015 +0200

    initscript: move to functions

 pdns.init | 169 +++++++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 106 insertions(+), 63 deletions(-)
---
diff --git a/pdns.init b/pdns.init
index 87965ed..c29d0ea 100755
--- a/pdns.init
+++ b/pdns.init
@@ -44,89 +44,94 @@ doPC() {
 doPC ping
 NOTRUNNING=$?
 
-RETVAL=0
-case "$1" in
-  status)
-	status pdns_server
-	exit $?
-	;;
-  stop)
-	if test "$NOTRUNNING" = "0"; then
-		msg_stopping "PowerDNS"
-		doPC quit 2>&1 >/dev/null
-		[ $? -eq 0 ] && ok || fail
-		rm /var/lock/subsys/pdns
-	else
-		msg_not_running "PowerDNS"
-	fi
-	;;
-  force-stop)
-	run_cmd "Killing PowerDNS without grace" killall -v -9 pdns_server
-	;;
-  start)
+start() {
 	if test "$NOTRUNNING" = "0"; then
 		msg_already_running "PowerDNS"
-	else
-		msg_starting "PowerDNS (Powered DNS server)"
-		daemon $pdns_server --daemon --guardian=yes
-		RETVAL=$?
-		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/pdns
+		return
 	fi
-	;;
-  restart)
-	$0 stop
+
+	msg_starting "PowerDNS (Powered DNS server)"
+	daemon $pdns_server --daemon --guardian=yes
+	RETVAL=$?
+	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/pdns
+}
+
+stop() {
+	if test "$NOTRUNNING" != "0"; then
+		msg_not_running "PowerDNS"
+		return
+	fi
+
+	msg_stopping "PowerDNS"
+	doPC quit 2>&1 >/dev/null
+	[ $? -eq 0 ] && ok || fail
+	rm /var/lock/subsys/pdns
+}
+
+restart() {
+	stop
 	run_cmd "PowerDNS (3 sec. timeout)" sleep 3
-	$0 start
-	exit $?
-	;;
-  reload|force-reload)
-	if test "$NOTRUNNING" = "0"; then
-		show "Reloading PowerDNS"
-		doPC cycle 2>&1 >/dev/null
-		if [ $? -eq 0 ]; then
-			ok
-		else
-			fail
-			RETVAL=1
-		fi
-	else
+	start
+}
+
+reload() {
+	if test "$NOTRUNNING" != "0"; then
 		msg_not_running "PowerDNS" >&2
-		exit 7
+		RETVAL=7
+		return
 	fi
-	;;
-  monitor)
-	if test "$NOTRUNNING" = "0"; then
-		msg_already_running "PowerDNS"
+
+	show "Reloading PowerDNS"
+	doPC cycle 2>&1 >/dev/null
+	if [ $? -eq 0 ]; then
+		ok
 	else
-		show "PowerDNS in foreground (testing mode)"
-		$pdns_server --daemon=no --guardian=no --control-console --loglevel=9
+		fail
+		RETVAL=1
 	fi
-	;;
-  dump)
+}
+
+monitor() {
 	if test "$NOTRUNNING" = "0"; then
-		doPC list
-		echo $ret
-	else
+		msg_already_running "PowerDNS"
+		return
+	fi
+
+	show "PowerDNS in foreground (testing mode)"
+	$pdns_server --daemon=no --guardian=no --control-console --loglevel=9
+}
+
+dump() {
+	if test "$NOTRUNNING" != "0"; then
 		msg_not_running "PowerDNS"
+		return
 	fi
-	;;
-  show)
+
+	doPC list
+	echo $ret
+}
+
+show() {
 	if [ $# -lt 2 ]; then
 		msg_usage "$0 {show|mrtg|cricket} <variable_name_from_pdns_dump>"
-		exit 2
+		RETVAL=2
+		return
 	fi
+
 	if test "$NOTRUNNING" = "0"; then
 		echo -n "$2="
 		doPC show $2 ; echo $ret
 	else
 		msg_not_running "PowerDNS"
 	fi
-	;;
-  mrtg)
+}
+
+mrtg() {
 	if [ $# -lt 2 ]; then
 		msg_usage "$0 {show|mrtg|cricket} <variable_name_from_pdns_dump>"
-		exit 2
+		RETVAL=2
 	fi
+
 	if test "$NOTRUNNING" = "0"; then
 		doPC show $2 ; echo $ret
 		if [ "$3x" != "x" ]; then
@@ -140,18 +145,56 @@ case "$1" in
 		msg_not_running "PowerDNS" >&2
 		exit 7
 	fi
-	;;
-  cricket)
+}
+
+cricket() {
 	if [ $# -lt 2 ]; then
 		msg_usage "$0 {show|mrtg|cricket} <variable_name_from_pdns_dump>"
-		exit 2
+		RETVAL=2
 	fi
+
 	if test "$NOTRUNNING" = "0"; then
 		doPC show $2 ; echo $ret
 	else
 		msg_not_running "PowerDNS" >&2
 		exit 7
 	fi
+}
+
+RETVAL=0
+case "$1" in
+  stop)
+	stop
+	;;
+  force-stop)
+	run_cmd "Killing PowerDNS without grace" killall -v -9 pdns_server
+	;;
+  start)
+	start
+	;;
+  restart)
+	restart
+	;;
+  reload|force-reload)
+	reload
+	;;
+  monitor)
+	monitor
+	;;
+  dump)
+	dump
+	;;
+  show)
+	show "$@"
+	;;
+  mrtg)
+	mrtg "$@"
+	;;
+  cricket)
+	cricket "$@"
+	;;
+  status)
+	status pdns_server
 	;;
   *)
 	msg_usage "$0 {start|stop|restart|reload|force-reload|status|dump|show|mrtg|cricket|monitor} [...]"
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/pdns.git/commitdiff/5311dff8cce12b84bd681297669a9941ca271d8f



More information about the pld-cvs-commit mailing list