/[baselayout]/trunk/sh/rc-help.sh
Gentoo

Contents of /trunk/sh/rc-help.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2763 - (show annotations) (download) (as text)
Tue Jul 10 19:09:41 2007 UTC (7 years, 2 months ago) by uberlord
File MIME type: text/x-sh
File size: 7883 byte(s)
init scripts and their extra options can now have descriptions, #184327.
1 #!/bin/sh
2 # Copyright 1999-2007 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 if [ "${RC_NOCOLOR}" = "yes" ] ; then
6 unset BLUE GREEN OFF CYAN
7 else
8 BLUE="\033[34;01m"
9 GREEN="\033[32;01m"
10 OFF="\033[0m"
11 CYAN="\033[36;01m"
12 fi
13
14 myscript=$1
15 if [ -z "${myscript}" ] ; then
16 echo "Please execute an init.d script"
17 exit 1
18 fi
19
20 if [ -L "${myscript}" ] ; then
21 SERVICE=$(readlink "${myscript}")
22 else
23 SERVICE=${myscript}
24 fi
25 SERVICE=${SERVICE##*/}
26
27 if [ "$2" = "help" ] ; then
28 BE_VERBOSE="yes"
29 NL="\n"
30 else
31 BE_VERBOSE="no"
32 NL=
33 fi
34
35 default_opts="describe start stop restart pause zap"
36 extra_opts="$(. "${myscript}" 2>/dev/null ; echo "${opts}")"
37
38 if [ "${BE_VERBOSE}" = "yes" ] ; then
39 printf "
40 ${GREEN}Gentoo RC-Scripts; ${BLUE}http://www.gentoo.org/${OFF}
41 Copyright 1999-2007 Gentoo Foundation; Distributed under the GPL
42 "
43 fi
44
45 printf "Usage: ${CYAN}${SERVICE}${OFF} [ ${GREEN}flags${OFF} ] < ${GREEN}options${OFF} >
46
47 ${CYAN}Normal Options:${OFF}"
48
49 if [ "${BE_VERBOSE}" = "yes" ] ; then
50 printf "
51 ${GREEN}describe${OFF}
52 Describe what the service and any extra options do.
53
54 ${GREEN}start${OFF}
55 Start service, as well as the services it depends on (if not already
56 started).
57
58 ${GREEN}stop${OFF}
59 Stop service, as well as the services that depend on it (if not already
60 stopped).
61
62 ${GREEN}restart${OFF}
63 Restart service, as well as the services that depend on it.
64
65 Note to developers: If this function is replaced with a custom one,
66 'svc_start' and 'svc_stop' should be used instead of 'start' and
67 'stop' to restart the service. This is so that the dependencies
68 can be handled correctly. Refer to the portmap rc-script for an
69 example.
70
71 ${GREEN}conditionalrestart|condrestart${OFF}
72 Same as 'restart', but only if the service has already been started.
73
74 ${GREEN}zap${OFF}
75 Reset a service that is currently stopped, but still marked as started,
76 to the stopped state. Basically for killing zombie services.
77
78 ${GREEN}status${OFF}
79 Prints \"status: started\" if the service is running, else it
80 prints \"status: stopped\".
81
82 Note that if the '--quiet' flag is given, it will return true if the
83 service is running, else false.
84
85 ${GREEN}ineed|iuse${OFF}
86 List the services this one depends on. Consult the section about
87 dependencies for more info on the different types of dependencies.
88
89 ${GREEN}needsme|usesme${OFF}
90 List the services that depend on this one. Consult the section about
91 dependencies for more info on the different types of dependencies.
92
93 ${GREEN}broken${OFF}
94 List the missing or broken dependencies of type 'need' this service
95 depends on.
96 "
97
98 else
99
100 printf " ${GREEN}${default_opts}${OFF}
101 Default init.d options.
102 "
103
104 fi
105
106 if [ -n "${extra_opts}" ] ; then
107 printf "
108 ${CYAN}Additional Options:${OFF}${NL}
109 ${GREEN}${extra_opts}${OFF}
110 Extra options supported by this init.d script.
111 "
112 fi
113
114 printf "
115 ${CYAN}Flags:${OFF}${NL}
116 ${GREEN}--ifstarted${OFF} Only do actions if service started
117 ${GREEN}--nodeps${OFF} Don't stop or start any dependencies
118 ${GREEN}--quiet${OFF}
119 Suppress output to stdout, except if:${NL}
120 1) It is a warning, then output to stdout
121 2) It is an error, then output to stderr${NL}
122 ${GREEN}--verbose${OFF} Output extra information
123 ${GREEN}--debug${OFF} Output debug information
124 ${GREEN}--nocolor${OFF} Suppress the use of colors
125 "
126
127 if [ "${BE_VERBOSE}" = "yes" ] ; then
128 printf "
129 ${CYAN}Dependencies:${OFF}
130
131 This is the heart of the Gentoo RC-Scripts, as it determines the order
132 in which services gets started, and also to some extend what services
133 get started in the first place.
134
135 The following example demonstrates how to use dependencies in
136 rc-scripts:
137
138 depend() {
139 need foo bar
140 use ray
141 }
142
143 Here we have foo and bar as dependencies of type 'need', and ray of
144 type 'use'. You can have as many dependencies of each type as needed, as
145 long as there is only one entry for each type, listing all its dependencies
146 on one line only.
147
148 ${GREEN}need${OFF}
149 These are all the services needed for this service to start. If any
150 service in the 'need' line is not started, it will be started even if it
151 is not in the current, or 'boot' runlevel, and then this service will be
152 started. If any services in the 'need' line fails to start or is
153 missing, this service will never be started.
154
155 ${GREEN}use${OFF}
156 This can be seen as representing optional services this service depends on
157 that are not critical for it to start. For any service in the 'use' line,
158 it must be added to the 'boot' or current runlevel to be considered a
159 valid 'use' dependency. It can also be used to determine startup order.
160
161 ${GREEN}before${OFF}
162 This, together with the 'after' dependency type, can be used to control
163 startup order. In core, 'before' and 'after' do not denote a dependency,
164 but should be used for order changes that will only be honoured during
165 a change of runlevel. All services listed will get started *after* the
166 current service. In other words, this service will get started *before*
167 all listed services.
168
169 ${GREEN}after${OFF}
170 All services listed will be started *before* the current service. Have a
171 look at 'before' for more info.
172
173 ${GREEN}provide${OFF}
174 This is not really a dependency type, rather it will enable you to create
175 virtual services. This is useful if there is more than one version of
176 a specific service type, system loggers or crons for instance. Just
177 have each system logger provide 'logger', and make all services in need
178 of a system logger depend on 'logger'. This should make things much more
179 generic.
180
181 Note that the 'need', 'use', 'before', and 'after' dependency types accept
182 an '*' as an argument. Having:
183
184 depend() {
185 before *
186 }
187
188 will make the service start first in the current runlevel, and:
189
190 depend() {
191 after *
192 }
193
194 will make the service the last to start.
195
196 You should however be careful how you use this, as I really will not
197 recommend using it with the 'need' or 'use' dependency type ... you have
198 been warned!
199
200 ${CYAN}'net' Dependency and 'net.*' Services:${OFF}
201
202 Example:
203
204 depend() {
205 need net
206 }
207
208 This is a special dependency of type 'need'. It represents a state where
209 a network interface or interfaces besides lo is up and active. Any service
210 starting with 'net.' will be treated as a part of the 'net' dependency,
211 if:
212
213 1. It is part of the 'boot' runlevel
214 2. It is part of the current runlevel
215
216 A few examples are the /etc/init.d/net.eth0 and /etc/init.d/net.lo services.
217 "
218 fi
219
220 printf "
221 ${CYAN}Configuration files:${OFF}
222 "
223
224 if [ "${BE_VERBOSE}" = "yes" ] ; then
225 printf "
226 There are two files which will be sourced for possible configuration by
227 the rc-scripts. They are (sourced from top to bottom):
228 "
229 fi
230
231 printf " /etc/conf.d/${SERVICE}${NL} /etc/rc.conf"
232
233 if [ "${BE_VERBOSE}" = "yes" ] ; then
234 printf "
235 You can add extra dependencies to ${SERVICE} by adding some variables to
236 /etc/conf.d/${SERVICE}
237 RC_NEED=\"openvpn ntpd\"
238 RC_USE=\"dns\"
239
240 This makes ${SERVICE} need openvpn and ntpd, while it just uses dns.
241
242 A good example of this is nfsmount needing openvpn if the nfs mounts in
243 /etc/fstab are over the vpn link.
244 "
245 fi
246
247 if [ "${BE_VERBOSE}" = "yes" ] ; then
248 printf "\n
249 ${CYAN}Management:${OFF}
250
251 Services are added and removed via the 'rc-update' tool. Running it without
252 arguments should give sufficient help.
253 "
254 else
255 printf "\n
256 For more info, please run '${myscript} help'.
257 "
258 fi
259
260 exit 0

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20