[RFC PATCH 03/12] init-d-script: allow scripts to disable --exec or --name options
Trek
trek00 at inbox.ru
Thu Jul 2 18:18:23 BST 2020
This is useful in conjunction with --startas or when other matching
options are specified, like --user and --pidfile, or when --exec or
--name cannot be easily guessed at packaging time.
---
debian/init-d-script | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/debian/init-d-script b/debian/init-d-script
index 13da61eb..b3204025 100755
--- a/debian/init-d-script
+++ b/debian/init-d-script
@@ -45,8 +45,10 @@ call() {
do_start_cmd() {
start-stop-daemon --start --quiet --oknodo \
- ${PIDFILE:+--pidfile ${PIDFILE}} $START_ARGS \
- --name ${COMMAND_NAME} --exec $DAEMON -- $DAEMON_ARGS
+ $START_ARGS \
+ ${PIDFILE:+--pidfile "$PIDFILE"} \
+ ${COMMAND_NAME:+--name "$COMMAND_NAME"} \
+ ${DAEMON:+--exec "$DAEMON"} -- $DAEMON_ARGS
}
do_start()
@@ -75,7 +77,9 @@ do_start()
do_stop_cmd() {
start-stop-daemon --stop --quiet --oknodo --retry=TERM/30/KILL/5 \
$STOP_ARGS \
- ${PIDFILE:+--pidfile ${PIDFILE}} --name ${COMMAND_NAME} --exec $DAEMON
+ ${PIDFILE:+--pidfile "$PIDFILE"} \
+ ${COMMAND_NAME:+--name "$COMMAND_NAME"} \
+ ${DAEMON:+--exec "$DAEMON"}
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
@@ -84,10 +88,11 @@ do_stop_cmd() {
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
- start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 \
- $STOP_ARGS \
- --exec $DAEMON
- [ "$?" = 2 ] && return 2
+ if [ -n "$DAEMON" ] ; then
+ start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 \
+ $STOP_ARGS --exec "$DAEMON"
+ [ "$?" = 2 ] && return 2
+ fi
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return $RETVAL
@@ -147,7 +152,9 @@ do_reload_sigusr1() {
fi
log_daemon_msg "Reloading $DESC configuration files" "$NAME"
start-stop-daemon --oknodo --stop --signal 1 --quiet \
- --pidfile "$PIDFILE" --exec "$DAEMON"
+ ${PIDFILE:+--pidfile ${PIDFILE}} \
+ ${COMMAND_NAME:+--name "$COMMAND_NAME"} \
+ ${DAEMON:+--exec "$DAEMON"}
log_end_msg $?
if is_call_implemented do_reload_cleanup ; then
call do_reload_cleanup
@@ -194,6 +201,10 @@ if [ none != "$DAEMON" ] && [ ! -x "$DAEMON" ] ; then
exit 0
fi
+# Do not use DAEMON or COMMAND_NAME if they are set to 'none'.
+[ none = "$DAEMON" ] && DAEMON=
+[ none = "$COMMAND_NAME" ] && COMMAND_NAME=
+
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
if [ -t 0 ] ; then # Be verbose when called from a terminal
--
2.20.1
More information about the Debian-init-diversity
mailing list