[PATCH 5/9] init-d-script: added do_reload_cmd interface

Trek trek00 at inbox.ru
Fri Aug 28 07:21:27 BST 2020


If the function do_reload_cmd is implemented but do_reload is not,
do_reload is aliased to do_reload_wrapper, that calls do_reload_cmd
without the need to add the usual boilerplate.
---
 debian/init-d-script   | 22 ++++++++++++++++++++++
 debian/init-d-script.5 | 11 +++++++++++
 2 files changed, 33 insertions(+)

diff --git a/debian/init-d-script b/debian/init-d-script
index bc398752..1b763c65 100755
--- a/debian/init-d-script
+++ b/debian/init-d-script
@@ -125,6 +125,21 @@ do_restart() {
 	return $retval
 }
 
+# Wrapper for do_reload_cmd
+do_reload_wrapper() {
+	if is_call_implemented do_reload_prepare ; then
+		call do_reload_prepare
+	fi
+	vlog_daemon_msg "Reloading $DESC configuration files" "$NAME"
+	call do_reload_cmd
+	retval=$(( $? != 0 ))
+	vlog_end_msg $retval
+	if is_call_implemented do_reload_cleanup ; then
+		call do_reload_cleanup
+	fi
+	return $retval
+}
+
 # Enable this using
 # alias do_reload=do_reload_sigusr1
 do_reload_sigusr1() {
@@ -194,6 +209,13 @@ if [ -t 0 ] ; then # Be verbose when called from a terminal
     VERBOSE=yes
 fi
 
+# Setup do_reload if not already defined
+if ! is_call_implemented do_reload ; then
+	if is_call_implemented do_reload_cmd ; then
+		alias do_reload=do_reload_wrapper
+	fi
+fi
+
 case "$1" in
   start)
 	call do_start
diff --git a/debian/init-d-script.5 b/debian/init-d-script.5
index e372b515..bbfb5f0d 100644
--- a/debian/init-d-script.5
+++ b/debian/init-d-script.5
@@ -155,6 +155,17 @@ action; it should be implemented by the script writer by defining a
 .Fn do_reload
 function.
 .Pp
+If
+.Fn do_reload
+is not defined but
+.Fn do_reload_cmd
+is, the latter will be called on
+.Ic reload ,
+after
+.Fn do_reload_prepare
+and before
+.Fn do_reload_cleanup .
+.Pp
 If the daemon performs reload action upon receiving a
 .Dv SIGUSR1
 signal, a generic implementation can be used with the following code:
-- 
2.20.1




More information about the Debian-init-diversity mailing list