Runscript: allow extra_commands to be run in chroots
The commands defined in the extra_commands variable do not depend on whether the service is stopped or started, so it is valid to run them in chroot environments. Also, add a note to the runscript man page about the commands in extra_commands being able to run whether or not the service is started. Reported-by: Robin Johnson <robbat2@gentoo.org> X-Gentoo-Bug: 406713 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=406713
This commit is contained in:
parent
7a1e4ef606
commit
9fa54a8e80
@ -92,7 +92,8 @@ or stopping them.
|
|||||||
The following variables affect the service script:
|
The following variables affect the service script:
|
||||||
.Bl -tag -width "RC_DEFAULTLEVEL"
|
.Bl -tag -width "RC_DEFAULTLEVEL"
|
||||||
.It Ar extra_commands
|
.It Ar extra_commands
|
||||||
Space separated list of extra commands the service defines.
|
Space separated list of extra commands the service defines. These should
|
||||||
|
not depend on the service being stopped or started.
|
||||||
.It Ar extra_started_commands
|
.It Ar extra_started_commands
|
||||||
Space separated list of extra commands the service defines. These only work if
|
Space separated list of extra commands the service defines. These only work if
|
||||||
the service has already been started.
|
the service has already been started.
|
||||||
|
@ -4,6 +4,22 @@
|
|||||||
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
|
# Copyright (c) 2007-2009 Roy Marples <roy@marples.name>
|
||||||
# Released under the 2-clause BSD license.
|
# Released under the 2-clause BSD license.
|
||||||
|
|
||||||
|
verify_boot()
|
||||||
|
{
|
||||||
|
if [ ! -e ${RC_SVCDIR}/softlevel ]; then
|
||||||
|
eerror "You are attempting to run an openrc service on a"
|
||||||
|
eerror "system which openrc did not boot."
|
||||||
|
eerror "You may be inside a chroot or you may have used"
|
||||||
|
eerror "another initialization system to boot this system."
|
||||||
|
eerror "In this situation, you will get unpredictable results!"
|
||||||
|
eerror
|
||||||
|
eerror "If you really want to do this, issue the following command:"
|
||||||
|
eerror "touch ${RC_SVCDIR}/softlevel"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
sourcex()
|
sourcex()
|
||||||
{
|
{
|
||||||
if [ "$1" = "-e" ]; then
|
if [ "$1" = "-e" ]; then
|
||||||
@ -24,18 +40,6 @@ if sourcex -e "/sbin/livecd-functions.sh"; then
|
|||||||
livecd_read_commandline
|
livecd_read_commandline
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -e ${RC_SVCDIR}/softlevel ]; then
|
|
||||||
eerror "You are attempting to run an openrc service on a"
|
|
||||||
eerror "system which openrc did not boot."
|
|
||||||
eerror "You may be inside a chroot or you may have used"
|
|
||||||
eerror "another initialization system to boot this system."
|
|
||||||
eerror "In this situation, you will get unpredictable results!"
|
|
||||||
eerror
|
|
||||||
eerror "If you really want to do this, issue the following command:"
|
|
||||||
eerror "touch ${RC_SVCDIR}/softlevel"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$1" -o -z "$2" ]; then
|
if [ -z "$1" -o -z "$2" ]; then
|
||||||
eerror "$RC_SVCNAME: not enough arguments"
|
eerror "$RC_SVCNAME: not enough arguments"
|
||||||
exit 1
|
exit 1
|
||||||
@ -256,7 +260,7 @@ while [ -n "$1" ]; do
|
|||||||
# we can run this command
|
# we can run this command
|
||||||
for _cmd in $extra_started_commands; do
|
for _cmd in $extra_started_commands; do
|
||||||
if [ "$_cmd" = "$1" ]; then
|
if [ "$_cmd" = "$1" ]; then
|
||||||
if ! service_started; then
|
if verify_boot && ! service_started; then
|
||||||
eerror "$RC_SVCNAME: cannot \`$1' as it has not been started"
|
eerror "$RC_SVCNAME: cannot \`$1' as it has not been started"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -266,13 +270,16 @@ while [ -n "$1" ]; do
|
|||||||
# we can run this command
|
# we can run this command
|
||||||
for _cmd in $extra_stopped_commands; do
|
for _cmd in $extra_stopped_commands; do
|
||||||
if [ "$_cmd" = "$1" ]; then
|
if [ "$_cmd" = "$1" ]; then
|
||||||
if ! service_stopped; then
|
if verify_boot && ! service_stopped; then
|
||||||
eerror "$RC_SVCNAME: cannot \`$1' as it has not been stopped"
|
eerror "$RC_SVCNAME: cannot \`$1' as it has not been stopped"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
unset _cmd
|
unset _cmd
|
||||||
|
case $1 in
|
||||||
|
start|stop|status) verify_boot;;
|
||||||
|
esac
|
||||||
if [ "$(command -v "$1_pre")" = "$1_pre" ]
|
if [ "$(command -v "$1_pre")" = "$1_pre" ]
|
||||||
then
|
then
|
||||||
"$1"_pre || exit $?
|
"$1"_pre || exit $?
|
||||||
|
Loading…
Reference in New Issue
Block a user