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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20