[PATCH 6/9] init-d-script: added RELOAD_SIGNAL interface

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


If RELOAD_SIGNAL is defined but do_reload and do_reload_cmd are
not, do_reload_cmd is set to call do_reload_signal and the
configured signal is sent to the process on reload.

Thanks: Robbie Harwood <rharwood at club.cc.cmu.edu>
Closes: #807311
---
 debian/init-d-script   | 31 +++++++++++++++++--------------
 debian/init-d-script.5 | 22 +++++++++++++---------
 2 files changed, 30 insertions(+), 23 deletions(-)

diff --git a/debian/init-d-script b/debian/init-d-script
index 1b763c65..53515d10 100755
--- a/debian/init-d-script
+++ b/debian/init-d-script
@@ -140,22 +140,21 @@ do_reload_wrapper() {
 	return $retval
 }
 
+# To enable this function, RELOAD_SIGNAL should be set to the kill signal
+do_reload_signal() {
+	start-stop-daemon --stop --signal $RELOAD_SIGNAL --quiet \
+	    ${PIDFILE:+--pidfile "$PIDFILE"} \
+	    ${COMMAND_NAME:+--name "$COMMAND_NAME"} \
+	    ${DAEMON:+--exec "$DAEMON"} $RELOAD_ARGS
+}
+
+# Deprecated: use RELOAD_SIGNAL instead for newer scripts
 # Enable this using
 # alias do_reload=do_reload_sigusr1
 do_reload_sigusr1() {
-        if is_call_implemented do_reload_prepare ; then
-            call do_reload_prepare
-        fi
-        log_daemon_msg "Reloading $DESC configuration files" "$NAME"
-        start-stop-daemon --stop --signal 1 --quiet \
-	    ${PIDFILE:+--pidfile "$PIDFILE"} \
-	    ${DAEMON:+--exec "$DAEMON"}
-	retval=$(( $? != 0 ))
-	log_end_msg $retval
-        if is_call_implemented do_reload_cleanup ; then
-            call do_reload_cleanup
-        fi
-	return $retval
+	RELOAD_SIGNAL=1
+	do_reload_cmd() { do_reload_signal; }
+	do_reload_wrapper
 }
 
 do_status() {
@@ -169,7 +168,7 @@ fi
 # Unset configuration variables to make sure that if variable is not assigned a
 # value in init script, it does not use one from environment. See #822918.
 unset DAEMON DAEMON_ARGS DESC NAME COMMAND_NAME PIDFILE \
-    START_ARGS STOP_ARGS
+    RELOAD_ARGS RELOAD_SIGNAL START_ARGS STOP_ARGS
 
 SCRIPTNAME="$__init_d_script_name"
 scriptbasename="$(basename "$__init_d_script_name")"
@@ -211,6 +210,10 @@ fi
 
 # Setup do_reload if not already defined
 if ! is_call_implemented do_reload ; then
+	if ! is_call_implemented do_reload_cmd && [ -n "$RELOAD_SIGNAL" ]
+	then
+		do_reload_cmd() { do_reload_signal; }
+	fi
 	if is_call_implemented do_reload_cmd ; then
 		alias do_reload=do_reload_wrapper
 	fi
diff --git a/debian/init-d-script.5 b/debian/init-d-script.5
index bbfb5f0d..1d8a47be 100644
--- a/debian/init-d-script.5
+++ b/debian/init-d-script.5
@@ -29,7 +29,7 @@ DAEMON=/usr/sbin/atd
 .Ed
 .Pp
 The following variables affect behaviour of an init script:
-.Bl -tag -width "DAEMON_ARGS"
+.Bl -tag -width "RELOAD_SIGNAL"
 .It Ev DAEMON
 Path to daemon being started.
 If the init script is not supposed to start any kind of daemon,
@@ -72,15 +72,26 @@ If the value is verbatim
 the process identifier will not be stored in any file.
 If this variable is not set, it gets a sensible default value,
 so it is rarely necessary to set this variable explicitly.
+.It Ev RELOAD_SIGNAL
+Signal number or name (without the SIG prefix) that will be sent to
+the process on
+.Ic reload .
+If the daemon performs reload action upon receiving a
+.Dv SIGHUP
+signal, this variable should be set to
+.Dq Li 1
+or
+.Dq Li HUP .
 .El
 .Pp
 The variables
+.Ev RELOAD_ARGS ,
 .Ev START_ARGS
 and
 .Ev STOP_ARGS
 are additional arguments, passed to
 .Xr start\-stop\-daemon 8
-during start and stop actions, to override the default options.
+during reload, start and stop actions, to override the default options.
 .Pp
 Additionally, it is possible to change the behaviour of the resulting
 shell script by overriding some of the internal functions.
@@ -165,13 +176,6 @@ 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:
-.Bd -literal -offset indent
-alias do_reload=do_reload_sigusr1
-.Ed
 .Sh SEE ALSO
 .Xr inittab 8 ,
 .Xr service 8 ,
-- 
2.20.1




More information about the Debian-init-diversity mailing list