Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion man/openrc-run.8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion service-script-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ All service scripts are assumed to have the following functions:
```
start()
stop()
reload()
status()
```

Expand All @@ -117,6 +118,7 @@ script:
command=
command_args=
pidfile=
reloadsig=
```

Thus the 'smallest' service scripts can be half a dozen lines long
Expand All @@ -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
Expand Down Expand Up @@ -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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be adjusted before merging

(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.

Expand Down
7 changes: 5 additions & 2 deletions sh/openrc-run.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
27 changes: 27 additions & 0 deletions sh/start-stop-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions sh/supervise-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading