From 742a9c2466dfb8328018487da0660214c4a7cc85 Mon Sep 17 00:00:00 2001 From: Ferass El Hafidi Date: Wed, 1 Jul 2026 16:25:13 +0000 Subject: [PATCH 1/4] sh/*-daemon.sh: add default reload function In the past what has been recommended for having a way to reload a daemon's configuration was to write a reload() function manually. Over the years many openrc scripts in, for instance, Alpine aports that have a reload() function are pretty much all the same (manually using start-stop-daemon to send a signal). Provide a default reload function that does exactly that. Those service scripts now only have to define `reloadsig=` to the signal to be sent on reload, for example `reloadsig=HUP`, and can drop their custom reload function. Signed-off-by: Ferass El Hafidi --- sh/start-stop-daemon.sh | 27 +++++++++++++++++++++++++++ sh/supervise-daemon.sh | 13 +++++++++++++ 2 files changed, 40 insertions(+) diff --git a/sh/start-stop-daemon.sh b/sh/start-stop-daemon.sh index b87061285..9fdab4bb8 100644 --- a/sh/start-stop-daemon.sh +++ b/sh/start-stop-daemon.sh @@ -105,6 +105,33 @@ ssd_stop() eend $? "Failed to stop ${name:-$RC_SVCNAME}" } +ssd_reload() +{ + if [ -n $reloadsig ]; then + eerror "There is nothing for ${name:-$RC_SVCNAME} to reload." + return 0 + fi + + local _progress= + local startchroot="$(service_get_value "chroot")" + local startpidfile="$(service_get_value "pidfile")" + local startprocname="$(service_get_value "procname")" + chroot="${startchroot:-$chroot}" + pidfile="${startpidfile:-$pidfile}" + procname="${startprocname:-$procname}" + [ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0 + yesno "${command_progress}" && _progress=--progress + + ebegin "Reloading ${name:-$RC_SVCNAME}" + start-stop-daemon \ + ${procname:+--name} $procname \ + ${pidfile:+--pidfile} $chroot$pidfile \ + --signal ${reloadsig} \ + ${_progress} + + eend $? "Failed to reload ${name:-$RC_SVCNAME}" +} + ssd_status() { _status diff --git a/sh/supervise-daemon.sh b/sh/supervise-daemon.sh index cdb5ef6f1..e0f845066 100644 --- a/sh/supervise-daemon.sh +++ b/sh/supervise-daemon.sh @@ -82,6 +82,19 @@ supervise_stop() eend $? "Failed to stop ${name:-$RC_SVCNAME}" } +supervise_reload() +{ + if [ -n $reloadsig ]; then + eerror "There is nothing for ${name:-$RC_SVCNAME} to reload." + return 0 + fi + + local startchroot="$(service_get_value "chroot")" + local startpidfile="$(service_get_value "pidfile")" + ebegin "Reloading ${name:-$RC_SVCNAME}" + supervise-daemon "${RC_SVCNAME}" --signal $reloadsig +} + _check_supervised() { local child_pid start_time From e8cfd83105a68c118a455abc95e76998d418d4de Mon Sep 17 00:00:00 2001 From: Ferass El Hafidi Date: Wed, 1 Jul 2026 16:29:18 +0000 Subject: [PATCH 2/4] sh/openrc-run.sh: run default reload functions for {supervise,start-stop}-daemon Signed-off-by: Ferass El Hafidi --- sh/openrc-run.sh.in | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sh/openrc-run.sh.in b/sh/openrc-run.sh.in index 50fc54c90..c20ef2336 100644 --- a/sh/openrc-run.sh.in +++ b/sh/openrc-run.sh.in @@ -205,13 +205,16 @@ default_status() default_reload() { + local func=ssd_reload case "$supervisor" in - s6) s6_reload ;; + s6) func=s6_reload ;; + supervise-daemon) func=supervise_reload ;; ?*) eerror "$RC_SVCNAME: undefined function 'reload'" exit 1 ;; esac + $func } # Template start / stop / status functions @@ -380,7 +383,7 @@ if yesno $IN_BACKGROUND; then done fi -for _cmd in $extra_started_commands; do +for _cmd in reload $extra_started_commands; do [ "$_cmd" = "$_func" ] || continue if verify_boot && ! service_started; then eerror "$RC_SVCNAME: cannot '$_func' as it has not been started" From b238a03d3e3801fe804efd312965f33c1edd8619 Mon Sep 17 00:00:00 2001 From: Ferass El Hafidi Date: Wed, 1 Jul 2026 16:29:57 +0000 Subject: [PATCH 3/4] service-script-guide.md: update to mention default reload function Signed-off-by: Ferass El Hafidi --- service-script-guide.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/service-script-guide.md b/service-script-guide.md index 596f516f3..43d2bfca8 100644 --- a/service-script-guide.md +++ b/service-script-guide.md @@ -103,6 +103,7 @@ All service scripts are assumed to have the following functions: ``` start() stop() +reload() status() ``` @@ -117,6 +118,7 @@ script: command= command_args= pidfile= +reloadsig= ``` Thus the 'smallest' service scripts can be half a dozen lines long @@ -131,6 +133,7 @@ following OpenRC variables are likely all that you'll need: * command * command_args * pidfile + * reloadsig Given those three pieces of information, OpenRC will be able to start and stop the daemon on its own. The following is taken from an @@ -242,7 +245,17 @@ To recap, in order of preference: Many daemons will reload their configuration files in response to a signal. Suppose your daemon will reload its configuration in response -to a `SIGHUP`. It's possible to add a new "reload" command to your +to a `SIGHUP`. You can simply add the following to your service script: + +```sh +reloadsig=HUP +``` + +For most daemons this is sufficient, though note it only works on OpenRC TODO. +(older versions need a custom `reload()` function, see below) + +If this approach is not enough, or the daemon has a completely different +way of reloading, it's still possible to add a new "reload" command to your service script that performs this action. First, tell the service script about the new command. From 29c7c3299a2aab555f1c8e3c36d3ee93111cc426 Mon Sep 17 00:00:00 2001 From: Ferass El Hafidi Date: Wed, 1 Jul 2026 16:46:22 +0000 Subject: [PATCH 4/4] man/openrc-run.8: document reload and reloadsig= Signed-off-by: Ferass El Hafidi --- man/openrc-run.8 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/man/openrc-run.8 b/man/openrc-run.8 index 436c0305c..28f0ca359 100644 --- a/man/openrc-run.8 +++ b/man/openrc-run.8 @@ -8,7 +8,7 @@ .\" This file may not be copied, modified, propagated, or distributed .\" except according to the terms contained in the LICENSE file. .\" -.Dd February 14, 2026 +.Dd July 1, 2026 .Dt openrc-run 8 SMM .Os OpenRC .Sh NAME @@ -51,6 +51,9 @@ Stops and starts the service, including dependencies. This cannot be overridden. See the description of the RC_CMD variable below for the method to make your service behave differently when restart is being executed. +.It Ar reload +Sends a signal to the service to reload its configuration. The signal to +send is defined by the reloadsig variable. .It Ar status Shows the status of the service. The return code matches the status, with the exception of "started" returning 0 to match standard command behaviour. @@ -207,6 +210,8 @@ Pidfile to use for the above defined command. Display name used for the above defined command. .It Ar procname Process name to match when signaling the daemon. +.It Ar reloadsig +Signal to send when reloading the daemon. .It Ar stopsig Signal to send when stopping the daemon. If using