diff options
Diffstat (limited to 'sh')
-rw-r--r-- | sh/runscript.sh.in | 35 |
1 files changed, 21 insertions, 14 deletions
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 <roy@marples.name> # 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 $? |