[RFC PATCH 11/12] init-d-script: added do_reload_cmd and RELOAD_SIGNAL interfaces
Trek
trek00 at inbox.ru
Thu Jul 2 18:19:43 BST 2020
If the function do_reload_cmd is implemented, it is called on
reload without the need to add the usual boilerplate.
If RELOAD_SIGNAL is defined, do_reload_signal is aliased to
do_reload_cmd and the configured signal is sent to the process.
If the function do_reload is implemented, none of the above
will be done as it was before.
---
debian/init-d-script | 46 +++++++++++++++++++++++++++++++-------------
1 file changed, 33 insertions(+), 13 deletions(-)
diff --git a/debian/init-d-script b/debian/init-d-script
index fbd1c633..749199a9 100755
--- a/debian/init-d-script
+++ b/debian/init-d-script
@@ -130,21 +130,15 @@ do_restart() {
# 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
- vlog_daemon_msg "Reloading $DESC configuration files" "$NAME"
- start-stop-daemon --stop --signal 1 --quiet \
- ${PIDFILE:+--pidfile ${PIDFILE}} \
+ RELOAD_SIGNAL=1 do_reload_wrapper do_reload_signal
+}
+
+# To enable set RELOAD_SIGNAL or add: alias do_reload_cmd=do_reload_signal
+do_reload_signal() {
+ start-stop-daemon --stop --signal "${RELOAD_SIGNAL:-1}" --quiet \
+ ${PIDFILE:+--pidfile "$PIDFILE"} \
${COMMAND_NAME:+--name "$COMMAND_NAME"} \
${DAEMON:+--exec "$DAEMON"}
- test $? -eq 0
- retval=$?
- vlog_end_msg $retval
- if is_call_implemented do_reload_cleanup ; then
- call do_reload_cleanup
- fi
- return $retval
}
do_status() {
@@ -197,6 +191,32 @@ if [ -t 0 ] ; then # Be verbose when called from a terminal
VERBOSE=yes
fi
+[ -n "$RELOAD_SIGNAL" ] && ! is_call_implemented do_reload_cmd &&
+ alias do_reload_cmd=do_reload_signal
+
+# 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"
+ if [ $# -eq 1 ] ; then
+ $1
+ else
+ do_reload_cmd
+ fi
+ test $? -eq 0
+ retval=$?
+ vlog_end_msg $retval
+ if is_call_implemented do_reload_cleanup ; then
+ call do_reload_cleanup
+ fi
+ return $retval
+}
+
+is_call_implemented do_reload_cmd && ! is_call_implemented do_reload &&
+ alias do_reload=do_reload_wrapper
+
case "$1" in
start)
call do_start
--
2.20.1
More information about the Debian-init-diversity
mailing list