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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20