runscript.sh: add chroot support

This adds support for a chroot variable which will be passed to the
start-stop-daemon --chroot switch to runscript.sh when starting a
daemon. This also needs to be saved so it can be used in locating the
pid file when stopping the daemon.

X-Gentoo-Bug: 524388
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=524388
This commit is contained in:
William Hubbs 2014-10-19 19:36:57 -05:00
parent 5f1439f1aa
commit 8c7ea4e9e8
2 changed files with 8 additions and 1 deletions

View File

@ -120,6 +120,9 @@ Set this to "true", "yes" or "1" (case-insensitive) to force the daemon into
the background. This implies the "--make-pidfile" and "--pidfile" option of the background. This implies the "--make-pidfile" and "--pidfile" option of
.Xr start-stop-daemon 8 .Xr start-stop-daemon 8
so the pidfile variable must be set. so the pidfile variable must be set.
.It Ar chroot
.Xr start-stop-daemon 8
will chroot into this path before writing the pid file or starting the daemon.
.It Ar pidfile .It Ar pidfile
Pidfile to use for the above defined command. Pidfile to use for the above defined command.
.It Ar name .It Ar name

View File

@ -142,12 +142,14 @@ start()
fi fi
eval start-stop-daemon --start \ eval start-stop-daemon --start \
--exec $command \ --exec $command \
${chroot:+--chroot} $chroot \
${procname:+--name} $procname \ ${procname:+--name} $procname \
${pidfile:+--pidfile} $pidfile \ ${pidfile:+--pidfile} $pidfile \
$_background $start_stop_daemon_args \ $_background $start_stop_daemon_args \
-- $command_args -- $command_args
if eend $? "Failed to start $RC_SVCNAME"; then if eend $? "Failed to start $RC_SVCNAME"; then
service_set_value "command" "${command}" service_set_value "command" "${command}"
[ -n "${chroot}" ] && service_set_value "chroot" "${chroot}"
[ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}" [ -n "${pidfile}" ] && service_set_value "pidfile" "${pidfile}"
[ -n "${procname}" ] && service_set_value "procname" "${procname}" [ -n "${procname}" ] && service_set_value "procname" "${procname}"
return 0 return 0
@ -163,9 +165,11 @@ start()
stop() stop()
{ {
local startcommand="$(service_get_value "command")" local startcommand="$(service_get_value "command")"
local startchroot="$(service_get_value "chroot")"
local startpidfile="$(service_get_value "pidfile")" local startpidfile="$(service_get_value "pidfile")"
local startprocname="$(service_get_value "procname")" local startprocname="$(service_get_value "procname")"
command="${startcommand:-$command}" command="${startcommand:-$command}"
chroot="${startchroot:-$chroot}"
pidfile="${startpidfile:-$pidfile}" pidfile="${startpidfile:-$pidfile}"
procname="${startprocname:-$procname}" procname="${startprocname:-$procname}"
[ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0 [ -n "$command" -o -n "$procname" -o -n "$pidfile" ] || return 0
@ -174,7 +178,7 @@ stop()
${retry:+--retry} $retry \ ${retry:+--retry} $retry \
${command:+--exec} $command \ ${command:+--exec} $command \
${procname:+--name} $procname \ ${procname:+--name} $procname \
${pidfile:+--pidfile} $pidfile \ ${pidfile:+--pidfile} $chroot$pidfile \
${stopsig:+--signal} $stopsig ${stopsig:+--signal} $stopsig
eend $? "Failed to stop $RC_SVCNAME" eend $? "Failed to stop $RC_SVCNAME"
} }