1 |
commit: 9fa54a8e8036262a7ea599d68e04fcbd8213506e |
2 |
Author: William Hubbs <williamh <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Mar 3 15:16:27 2012 +0000 |
4 |
Commit: William Hubbs <williamh <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Mar 3 15:22:44 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=9fa54a8e |
7 |
|
8 |
Runscript: allow extra_commands to be run in chroots |
9 |
|
10 |
The commands defined in the extra_commands variable do not depend on |
11 |
whether the service is stopped or started, so it is valid to run them in |
12 |
chroot environments. |
13 |
|
14 |
Also, add a note to the runscript man page about the commands in |
15 |
extra_commands being able to run whether or not the service is started. |
16 |
|
17 |
Reported-by: Robin Johnson <robbat2 <AT> gentoo.org> |
18 |
X-Gentoo-Bug: 406713 |
19 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=406713 |
20 |
|
21 |
--- |
22 |
man/runscript.8 | 3 ++- |
23 |
sh/runscript.sh.in | 35 +++++++++++++++++++++-------------- |
24 |
2 files changed, 23 insertions(+), 15 deletions(-) |
25 |
|
26 |
diff --git a/man/runscript.8 b/man/runscript.8 |
27 |
index 3b037ce..64f36b1 100644 |
28 |
--- a/man/runscript.8 |
29 |
+++ b/man/runscript.8 |
30 |
@@ -92,7 +92,8 @@ or stopping them. |
31 |
The following variables affect the service script: |
32 |
.Bl -tag -width "RC_DEFAULTLEVEL" |
33 |
.It Ar extra_commands |
34 |
-Space separated list of extra commands the service defines. |
35 |
+Space separated list of extra commands the service defines. These should |
36 |
+not depend on the service being stopped or started. |
37 |
.It Ar extra_started_commands |
38 |
Space separated list of extra commands the service defines. These only work if |
39 |
the service has already been started. |
40 |
|
41 |
diff --git a/sh/runscript.sh.in b/sh/runscript.sh.in |
42 |
index 83db42b..15cdb86 100644 |
43 |
--- a/sh/runscript.sh.in |
44 |
+++ b/sh/runscript.sh.in |
45 |
@@ -4,6 +4,22 @@ |
46 |
# Copyright (c) 2007-2009 Roy Marples <roy@×××××××.name> |
47 |
# Released under the 2-clause BSD license. |
48 |
|
49 |
+verify_boot() |
50 |
+{ |
51 |
+ if [ ! -e ${RC_SVCDIR}/softlevel ]; then |
52 |
+ eerror "You are attempting to run an openrc service on a" |
53 |
+ eerror "system which openrc did not boot." |
54 |
+ eerror "You may be inside a chroot or you may have used" |
55 |
+ eerror "another initialization system to boot this system." |
56 |
+ eerror "In this situation, you will get unpredictable results!" |
57 |
+ eerror |
58 |
+ eerror "If you really want to do this, issue the following command:" |
59 |
+ eerror "touch ${RC_SVCDIR}/softlevel" |
60 |
+ exit 1 |
61 |
+ fi |
62 |
+ return 0 |
63 |
+} |
64 |
+ |
65 |
sourcex() |
66 |
{ |
67 |
if [ "$1" = "-e" ]; then |
68 |
@@ -24,18 +40,6 @@ if sourcex -e "/sbin/livecd-functions.sh"; then |
69 |
livecd_read_commandline |
70 |
fi |
71 |
|
72 |
-if [ ! -e ${RC_SVCDIR}/softlevel ]; then |
73 |
- eerror "You are attempting to run an openrc service on a" |
74 |
- eerror "system which openrc did not boot." |
75 |
- eerror "You may be inside a chroot or you may have used" |
76 |
- eerror "another initialization system to boot this system." |
77 |
- eerror "In this situation, you will get unpredictable results!" |
78 |
- eerror |
79 |
- eerror "If you really want to do this, issue the following command:" |
80 |
- eerror "touch ${RC_SVCDIR}/softlevel" |
81 |
- exit 1 |
82 |
-fi |
83 |
- |
84 |
if [ -z "$1" -o -z "$2" ]; then |
85 |
eerror "$RC_SVCNAME: not enough arguments" |
86 |
exit 1 |
87 |
@@ -256,7 +260,7 @@ while [ -n "$1" ]; do |
88 |
# we can run this command |
89 |
for _cmd in $extra_started_commands; do |
90 |
if [ "$_cmd" = "$1" ]; then |
91 |
- if ! service_started; then |
92 |
+ if verify_boot && ! service_started; then |
93 |
eerror "$RC_SVCNAME: cannot \`$1' as it has not been started" |
94 |
exit 1 |
95 |
fi |
96 |
@@ -266,13 +270,16 @@ while [ -n "$1" ]; do |
97 |
# we can run this command |
98 |
for _cmd in $extra_stopped_commands; do |
99 |
if [ "$_cmd" = "$1" ]; then |
100 |
- if ! service_stopped; then |
101 |
+ if verify_boot && ! service_stopped; then |
102 |
eerror "$RC_SVCNAME: cannot \`$1' as it has not been stopped" |
103 |
exit 1 |
104 |
fi |
105 |
fi |
106 |
done |
107 |
unset _cmd |
108 |
+ case $1 in |
109 |
+ start|stop|status) verify_boot;; |
110 |
+ esac |
111 |
if [ "$(command -v "$1_pre")" = "$1_pre" ] |
112 |
then |
113 |
"$1"_pre || exit $? |