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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2849 - (show annotations) (download) (as text)
Sat Aug 25 18:17:05 2007 UTC (6 years, 11 months ago) by vapier
File MIME type: text/x-sh
File size: 8329 byte(s)
Make sure we list all config files in rc help output.
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 ${GREEN}config${OFF}
182 This is not really a dependency type, rather it informs the dependency
183 system about config files that may affect the dependencies of the service.
184 One example of this is the netmount service which changes its dependencies
185 depending on the config of /etc/fstab.
186
187 Note that the 'need', 'use', 'before', and 'after' dependency types accept
188 an '*' as an argument. Having:
189
190 depend() {
191 before *
192 }
193
194 will make the service start first in the current runlevel, and:
195
196 depend() {
197 after *
198 }
199
200 will make the service the last to start.
201
202 You should however be careful how you use this, as I really will not
203 recommend using it with the 'need' or 'use' dependency type ... you have
204 been warned!
205
206 ${CYAN}'net' Dependency and 'net.*' Services:${OFF}
207
208 Example:
209
210 depend() {
211 need net
212 }
213
214 This is a special dependency of type 'need'. It represents a state where
215 a network interface or interfaces besides lo is up and active. Any service
216 starting with 'net.' will be treated as a part of the 'net' dependency,
217 if:
218
219 1. It is part of the 'boot' runlevel
220 2. It is part of the current runlevel
221
222 A few examples are the /etc/init.d/net.eth0 and /etc/init.d/net.lo services.
223 "
224 fi
225
226 printf "
227 ${CYAN}Configuration files:${OFF}
228 "
229
230 if [ "${BE_VERBOSE}" = "yes" ] ; then
231 printf "
232 There are two files which will be sourced for possible configuration by
233 the rc-scripts. They are (sourced from left to right, top to bottom):
234 "
235 fi
236
237 printf " /etc/conf.d/rc${NL:- } /etc/conf.d/rc.${SOFTLEVEL}"
238 printf " /etc/conf.d/${SERVICE}${NL} /etc/conf.d/${SERVICE}.${SOFTLEVEL}"
239 printf " /etc/rc.conf"
240
241 if [ "${BE_VERBOSE}" = "yes" ] ; then
242 printf "
243 You can add extra dependencies to ${SERVICE} by adding some variables to
244 /etc/conf.d/${SERVICE}
245 RC_NEED=\"openvpn ntpd\"
246 RC_USE=\"dns\"
247
248 This makes ${SERVICE} need openvpn and ntpd, while it just uses dns.
249
250 A good example of this is nfsmount needing openvpn if the nfs mounts in
251 /etc/fstab are over the vpn link.
252 "
253 fi
254
255 if [ "${BE_VERBOSE}" = "yes" ] ; then
256 printf "\n
257 ${CYAN}Management:${OFF}
258
259 Services are added and removed via the 'rc-update' tool. Running it without
260 arguments should give sufficient help.
261 "
262 else
263 printf "\n
264 For more info, please run '${myscript} help'.
265 "
266 fi
267
268 exit 0

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.20