Thu, 05 Nov 2009 13:42:13 +0100
Resynchronize with upstream package maintainer version.
This is needed due to large changeset after upgrade of vendor
distribution from version 1.1.* to 1.2.*.
1 ##
2 ## rc.pod -- RPM Auxiliary Tool (Manual Page)
3 ## Copyright (c) 2000-2007 OpenPKG Foundation e.V. <http://openpkg.net/>
4 ## Copyright (c) 2000-2007 Ralf S. Engelschall <http://engelschall.com/>
5 ##
6 ## Permission to use, copy, modify, and distribute this software for
7 ## any purpose with or without fee is hereby granted, provided that
8 ## the above copyright notice and this permission notice appear in all
9 ## copies.
10 ##
11 ## THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
12 ## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
13 ## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
14 ## IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
15 ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
16 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
17 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18 ## USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
19 ## ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20 ## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
21 ## OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22 ## SUCH DAMAGE.
23 ##
25 =pod
27 =head1 NAME
29 B<@l_prefix@/bin/openpkg rc> - OpenPKG Run-Command Processor
31 =head1 SYNOPSIS
33 B<@l_prefix@/bin/openpkg rc> [B<-s>|B<--silent>] [B<-v>|B<--verbose>] [B<-d>|B<--debug>] [B<-k>|B<--keep>] I<package> I<command> [I<command> ...]
35 B<@l_prefix@/bin/openpkg rc> B<-p>|B<--print> I<package> I<command> [I<command> ...]
37 eval `B<@l_prefix@/bin/openpkg rc> B<-e>|B<--eval> I<package> I<command> [I<command> ...]`
39 B<@l_prefix@/bin/openpkg rc> B<-q>|B<--query> I<variable> [I<variable> ...]
41 B<@l_prefix@/bin/openpkg rc> B<-c>|B<--config>
43 B<@l_prefix@/bin/openpkg rc> B<-h>|B<--help>
45 =head1 DESCRIPTION
47 The B<@l_prefix@/bin/openpkg rc> program is the run-command (rc) processor
48 of the B<OpenPKG> instance C<@l_prefix@>. It allows querying the rc
49 configuration variables and the execution of rc command scripts of one
50 or more installed B<OpenPKG> packages. The implemented run-command
51 facility is partly modeled after the classical UNIX(tm) System V
52 run-command facility plus ideas taken from the FreeBSD and NetBSD
53 run-command facilities. It mainly merges the classical startup/shutdown
54 procedures with periodical procedures into a single approach.
56 =head1 USAGE
58 =over 4
60 =item B<@l_prefix@/bin/openpkg rc> [B<-s>|B<--silent>] [B<-v>|B<--verbose>] [B<-d>|B<--debug>] [B<-k>|B<--keep>] I<package> I<command> [I<command> ...]
62 B<Run-Command Execution.> This executes one or more specified
63 I<command>s in a particular I<package> or in all installed packages if
64 I<package> is "C<all>". Option B<--silent> can be used to explicitly
65 disable progress messages on C<stderr>. Option B<--verbose> can be used
66 to explicitly enable progress messages on C<stderr>. By default, B<rc>
67 automatically determines whether progress messages should be displayed
68 or not depending on whether C<stderr> is connected to a terminal device.
69 Option B<--keep> can be used for debugging purposes to keep the
70 temporary files were generated during internal processing.
72 =item B<@l_prefix@/bin/openpkg rc> B<-p>|B<--print> I<package> I<command> [I<command> ...]
74 B<Run-Command Printing.> This is like the run-command execution (see
75 above), but instead of immediately executing all involved individual
76 run-command scripts, they are concatenated (but with all configuration
77 parts reduced to a single configuration part) and printed to C<stdout>.
78 Use this for debugging or post-processing purposes.
80 =item eval `B<@l_prefix@/bin/openpkg rc> B<-e>|B<--eval> I<package> I<command> [I<command> ...]`
82 B<Run-Command Evaluation.> This is like the run-command execution
83 (see above), but the resulting exported shell environment variables
84 are output to a temporary file as a (Bourne-Shell or C-Shell syntax)
85 shell script, suitable for evaluation within the shell environment
86 of the caller. A one-line script is printed to C<stdout> which then
87 "sources" (and immediately removes) this temporary file. This is
88 slightly different from printing the temporary script directly to
89 C<stdout>, because not all shell implementations like to "B<eval>"
90 large multi-line scripts. Hence, use this for executing the "C<env>"
91 run-commands within the current shell.
93 =item B<@l_prefix@/bin/openpkg rc> B<-q>|B<--query> I<variable> [I<variable> ...]
95 B<Configuration Variable Querying.> This queries the effective values
96 (see B<RUN-COMMAND CONFIGURATION> section below) of one or more
97 run-command configuration I<variable>s. Use this within a shell script
98 to selectively query a particular variable.
100 =item B<@l_prefix@/bin/openpkg rc> B<-c>|B<--config>
102 B<Configuration Variable Summary.> This displays on C<stdout> a
103 three-column table showing the name, default and effective values of
104 all run-command configuration variables. If C<stdout> is connected to
105 terminal device, variables where the default and effective values differ
106 are shown in bold mode.
108 =item B<@l_prefix@/bin/openpkg rc> B<-h>|B<--help>
110 B<Requesting Help.> This just displays a short summary of
111 the usage for this program.
113 =back
115 =head1 FILES
117 =head2 RUN-COMMAND FILES (C<@l_prefix@/bin/openpkg rc.d/rc.*>)
119 The foundation of the B<OpenPKG> run-command facility are the individual
120 run-command files C<rc.*> of the installed packages. They are all
121 located in the directory C<@l_prefix@/bin/openpkg rc.d/> and are named
122 "C<rc.>I<package>". They consist of one or more sections, each starting
123 with a section header "C<%>I<name> [I<options>]" and following a GNU
124 Bash compatible shell script. There are three classes of sections:
126 =over 4
128 =item B<Special Sections>
130 There are 2 sections which have a special meaning to the B<rc> program
131 and cannot be used for different purposes.
133 =over 4
135 =item C<%config>
137 This section has to consist of run-command configuration
138 variable default settings in Bourne-Shell syntax only, i.e.,
139 it has to contain one or more lines, each of exactly the form
140 "I<package>C<_>I<variable>C<=>I<value>". Notice that in section
141 "C<%config>" of run-command file "C<rc.foo>" the variables all have
142 to be prefixed (by convention) with "C<foo_>". It is allowed that the
143 I<value>s reference other variables defined before in the same section
144 or from the "C<%config>" section of the bootstrap package "C<openpkg>".
145 Additionally, by convention all lines have to be indented by 4 spaces.
147 NOTICE: All sections of all run-command scripts see all C<%config>
148 sections of all packages.
150 =item C<%common>
152 This section can consist of an arbitrary shell script
153 which is automatically prepended to the shell scripts
154 of all other sections on execution. It is usually used
155 to define common and local variables and functions.
157 =back
159 =item B<Conventional Sections>
161 There are 9 sections which have no special meaning to the B<rc> program,
162 but are used in B<OpenPKG> by convention for standard purposes. Hence,
163 do not use them for arbitrary things instead.
165 Throughout these sections it is possible to specify the user to be
166 switched to before the code is executed.
168 A priority can be given for each section to control execution sequence
169 if "C<all>" packages are given. Higher priority leads to earlier
170 starting and later stopping. The priority is a number where low numbers
171 mean high priority (numerically sorted for starting). If omitted, the
172 priority defaults to 500.
174 Output generated on F<stdout> and F<stderr> is captured and normally
175 suppressed. In case the sections script exits with a non-zero return
176 value, the intercepted messages are consolidated, reformatted with a
177 surrounding ASCII-art border and printed to F<stderr>. If the section
178 is tagged with option B<-o>, F<stdout> messages are passed through
179 verbatim, even if the section script exists with a zero return value.
181 =over 4
183 =item C<%start> [B<-u> I<user>] [B<-p> I<priority>]
185 This section should start daemons or initialize components.
186 It is especially executed by B<OpenPKG> during system startup.
188 =item C<%stop> [B<-u> I<user>] [B<-p> I<priority>]
190 This section should stop daemons or cleaning up components. It is
191 especially executed by B<OpenPKG> during system shutdown and package
192 deinstallation.
194 =item C<%restart> [B<-u> I<user>] [B<-p> I<priority>]
196 This section should restart daemons.
197 It is especially executed by B<OpenPKG> during package upgrades.
199 =item C<%status -o> [B<-u> I<user>] [B<-p> I<priority>]
201 This section has to provide status information for a package
202 by printing to C<stdout> (hence the B<-o> option is always required),
203 in Bourne-Shell syntax, the definition of three variables:
205 =over 4
207 =item I<package>C<_enable>
209 Whether package is enabled, i.e., whether it accepts run-commands. This
210 variable just has to be printed, because is already set in current
211 script environment.
213 =item I<package>C<_usable>
215 Whether package is usable, i.e., whether it is already correctly
216 configured, etc. This variable has to be individually determined.
218 =item I<package>C<_active>
220 Whether package is active, i.e., whether it is already running.
221 This variable has to be individually determined.
223 =back
225 =item C<%monthly> [B<-u> I<user>] [B<-p> I<priority>]
227 =item C<%weekly> [B<-u> I<user>] [B<-p> I<priority>]
229 =item C<%hourly> [B<-u> I<user>] [B<-p> I<priority>]
231 =item C<%quarterly> [B<-u> I<user>] [B<-p> I<priority>]
233 These sections should perform periodical tasks for a package and
234 are executed on a monthly, weekly, hourly or quarterly basis.
236 =item C<%env>
238 This section is intended to export one or more environment variables
239 which are imported into the shell environment of the caller through the
240 B<--eval> command line option.
242 =back
244 =item B<Custom Sections>
246 All other sections are custom ones and can be fully individual to each
247 package. Some often seen sections are C<%reload> (just reload the
248 configuration without full stop and start procedure), C<%info> (output
249 arbitrary information about package), etc.
251 =back
253 =head2 RUN-COMMAND CONFIGURATION (C<@l_prefix@/bin/openpkg rc.conf>)
255 The run-command configuration variables defined in the "C<%config>"
256 sections of all installed packages can be overridden by the
257 administrator in the global file C<@l_prefix@/bin/openpkg rc.conf>. This file is
258 usually empty, but can be filled with Bourne-Shell compatible variable
259 assignment statements like "I<package>C<_>I<variable>=I<value>".
261 =head2 RUN-COMMAND FUNCTIONS (C<@l_prefix@/bin/openpkg rc.func>)
263 The file C<@l_prefix@/bin/openpkg rc.func> is prepended to the scripts of all
264 executed run-command sections and provides reusable functions.
265 Currently the following functions are defined:
267 =over 4
269 =item B<rcMsg> [B<-e>] [B<-w>] I<message>
271 Print a message to the output device of the run-command caller. The
272 message is printed to the captured F<stderr> (but are visible to
273 the caller of the run-command script only if the script fails). All
274 messages are prefixed with "C<rc:>". If option B<-e> is given, the
275 prefix is "C<rc:ERROR:>". If option B<-w> is given, the prefix is
276 "C<rc:WARNING:>".
278 =item B<rcPath> [B<-a>] [B<-r>] [B<-p>] [B<-e>] I<variable> I<dir> [I<dir> ...]
280 Add (option B<-a>) or remove (option B<-r>) one or more I<dir>ectories
281 to/from the colon-separated value of a I<var>able. By default, on
282 addition, the directory is appended to the end, if option B<-p> is used
283 the directory is prepended to the start. If option B<-e> is used, the
284 directories are added only if they exist on the underlying filesystem.
285 Use this function for conveniently manipulating C<PATH>, C<MANPATH>,
286 C<INFOPATH>, C<LD_LIBRARY_PATH> and similar variables.
288 =item B<rcTmp> [B<-i>] [B<-f>] [B<-n> I<name>] [B<-k>]
290 Convenience interface to secure temporary file handling. Option B<-i>
291 first has to be used to initialize a secure temporary directory (option
292 B<-k> later will kill this again). Under option B<-f> you then can get
293 reasonable temporary filenames under the created temporary directory. By
294 default, the temporary filename is just "C<tmp>", but can be specified
295 with option B<-n> to be I<name>.
297 =item B<rcService> I<package> I<status> I<value>
299 Convenience interface to checking the C<%status> variables
300 I<package>C<_>I<status> which have to be provided by the C<%config> (if
301 I<status> is "C<enable>" this is enough) and C<%status> (if I<status> is
302 "C<enable>", "C<usable>" and "C<active>"). The B<rcService> especially
303 caches the resolving of the variable values. Returns 0 if the resolved
304 value is I<value>, else returns 1.
306 =item B<rcVarIsYes> I<name>
308 Checks whether variable I<name> has a value of "C<yes>", "C<true>",
309 "C<on>", or "C<1>" (with arbitrary lower or upper case letters). Returns
310 0 if value is one of these positive ones, else returns 1.
312 =back
314 =head1 EXAMPLES
316 First, an example run-command script C<@l_prefix@/bin/openpkg rc.d/rc.foo> for a
317 fictional daemon package "C<foo>":
319 %config
320 foo_enable="${openpkg_rc_def}"
321 foo_listen="127.0.0.1"
322 foo_log_prolog="true"
323 foo_log_epilog="true"
324 foo_log_numfiles="10"
325 foo_log_minsize="1M"
326 foo_log_complevel="9"
328 %common
329 foo_homedir="@l_prefix@/share/foo"
330 foo_cfgfile="@l_prefix@/etc/foo/foo.cfg"
331 foo_pidfile="@l_prefix@/var/foo/foo.pid"
332 foo_logfile="@l_prefix@/var/foo/foo.log"
333 foo_signal () {
334 if [ -f ${foo_pidfile} ]; then
335 kill -$1 `cat ${foo_pidfile}`
336 return $?
337 else
338 return 1
339 fi
340 }
342 %status
343 foo_usable="no"
344 if [ ".`grep '<<PASSWORD>>' ${foo_cfgfile}`" = . ]; then
345 foo_usable="yes"
346 fi
347 foo_active="no"
348 if [ -f ${foo_pidfile} ]; then
349 foo_signal 0
350 if [ $? -eq 0 ]; then
351 foo_active="yes"
352 fi
353 fi
354 echo "foo_enable=${foo_enable}"
355 echo "foo_usable=${foo_usable}"
356 echo "foo_active=${foo_active}"
358 %start
359 rcService foo enable yes || exit 0
360 rcService foo active yes && exit 0
361 @l_prefix@/sbin/foo --listen ${foo_listen}
363 %stop
364 rcService foo enable yes || exit 0
365 rcService foo active yes || exit 0
366 foo_signal TERM
368 %restart
369 rcService foo enable yes || exit 0
370 rcService foo active yes || exit 0
371 rc foo stop start
373 %daily
374 rcService foo enable yes || exit 0
375 shtool rotate -f \
376 -n ${foo_log_numfiles} -s ${foo_log_minsize} -d \
377 -z ${foo_log_complevel} -o @l_rusr@ -g @l_rgrp@ -m 644 \
378 -P "${foo_log_prolog}" -E "${foo_log_epilog}" \
379 ${foo_logfile}
381 %env
382 if rcService foo enable yes; then
383 FOO_HOME="$foo_homedir"
384 export FOO_HOME
385 fi
387 Now, show all run-command configuration variables, their
388 default values and their effective values of package "C<foo>":
390 $ @l_prefix@/bin/openpkg rc --config | grep "^foo_"
392 Override the default value of a run-command configuration
393 variable C<foo_listen>:
395 $ echo 'foo_listen="192.168.0.1"' >>@l_prefix@/bin/openpkg rc.conf
397 Stop and start from scratch the package "C<foo>":
399 $ @l_prefix@/bin/openpkg rc foo stop start
401 Query the effective value of run-command configuration
402 variable C<foo_enable> in a script:
404 if [ ".`@l_prefix@/bin/openpkg rc -q foo_enable`" = .yes ]; then ...
406 Import all environment settings from all (including "C<foo>") installed
407 packages into the current Bourne-Shell environment:
409 $ eval `@l_prefix@/bin/openpkg rc --eval all env`
410 $ echo $FOO_HOME
412 =head1 SEE ALSO
414 B<OpenPKG> http://www.openpkg.org/
416 =head1 HISTORY
418 The B<OpenPKG> run-command facility consisting of the scripts C<rc>
419 and C<rc.func> were originally invented in November 2000 by Ralf S.
420 Engelschall for B<OpenPKG>. They were completely worked off from scratch
421 in July 2003 for B<OpenPKG 1.3>.
423 =head1 AUTHOR
425 Ralf S. Engelschall
426 rse@engelschall.com
427 www.engelschall.com
429 =cut