diff --git a/man/runscript.8 b/man/runscript.8 index 3b037ce7..64f36b15 100644 --- a/man/runscript.8 +++ b/man/runscript.8 @@ -92,7 +92,8 @@ or stopping them. The following variables affect the service script: .Bl -tag -width "RC_DEFAULTLEVEL" .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 Space separated list of extra commands the service defines. These only work if the service has already been started. diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in index 83db42b1..15cdb868 100644 --- a/sh/runscript.sh.in +++ b/sh/runscript.sh.in @@ -4,6 +4,22 @@ # Copyright (c) 2007-2009 Roy Marples # 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() { if [ "$1" = "-e" ]; then @@ -24,18 +40,6 @@ if sourcex -e "/sbin/livecd-functions.sh"; then livecd_read_commandline 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 eerror "$RC_SVCNAME: not enough arguments" exit 1 @@ -256,7 +260,7 @@ while [ -n "$1" ]; do # we can run this command for _cmd in $extra_started_commands; do 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" exit 1 fi @@ -266,13 +270,16 @@ while [ -n "$1" ]; do # we can run this command for _cmd in $extra_stopped_commands; do 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" exit 1 fi fi done unset _cmd + case $1 in + start|stop|status) verify_boot;; + esac if [ "$(command -v "$1_pre")" = "$1_pre" ] then "$1"_pre || exit $?