1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
|
lsb-base for Debian
-------------------
The Debian lsb-base package provides a series of logging functions to
permit simplified logging of init script actions. These functions are
specific to Debian and (in some cases) other derived distributions.
- log_daemon_msg "Starting/stopping long daemon name" "daemond"
Log starting/stopping of daemons. On Debian, outputs:
"Starting/stopping long daemon name: daemond"
and leaves the cursor at the end of the line. If "Fancy output" is
enabled, outputs:
"[....] Starting/stopping long daemon name: daemond"
and leaves the cursor at the end of the line.
- log_progress_msg "daemon2d"
Log startup of a second daemon (e.g. sysklogd, nfs init scripts).
On Debian, outputs " daemon2d" and leaves the cursor at the EOL.
- log_end_msg 0/1
Log successful startup. On Debian, outputs "." followed by newline.
A non-zero code may also be specified, which indicates failure;
currently implemented as outputting "failed!" (in red on a color
TTY) followed by newline.
Unsucessful startup will cause the specified failure code to be
returned by this function; unless trapped, this may end your init
script depending on whether or not set -e is used.
If "Fancy output" is enabled, it will store the cursor position,
move it to the start of the line, write a colored "[ ok ]", "[FAIL]"
or "[warn]" and restore the cursor position. This has the effect of
updating the "[....]" printed by log_daemon_msg.
- log_action_msg "Setting VARIABLE to VALUE"
Log an atomic action by your init script. Typically, this is the
setting of a kernel variable, but it might be something else that is
not expected to take any time (or fail).
On Debian, a trailing period will be added to the message, followed by
a newline. If "Fancy output" is enabled, the message will get prepended
with a blue [info].
- log_action_begin_msg "Configuring network interfaces"
Log the start of an action that is expected to take some time. On
Debian, an elipsis (...) will follow the message, and the cursor will
stay at EOL.
If "Fancy output" is enabled, it will get the same [....] block as
log_daemon_msg.
- log_action_cont_msg "flushing ARP cache"
Log an action as part of a process started by log_action_start_msg().
On Debian, this message will receive a trailing elipsis, and the cursor
will stay at EOL.
- log_action_end_msg {0|1} ["message"]
Log the end of the action started by log_action_start_msg(). If one
argument is supplied, either "done." (0) or "failed." (1) will be output,
followed by a newline. If a second argument is supplied, the message
will appear as follows:
"done (your message here)." --- if first argument is 0
"failed (your message here)." --- if first argument is 1
This argument must be quoted, or otherwise only the first word will
be output.
On color TTYs, the failure messages will be red.
Note that unlike log_end_msg(), this function does not return the
first argument as its exit code.
- status_of_proc [-p pidfile] pathname "Daemon_name"
Log the status of a process and return an LSB-compliant exit status
code:
0 program is running or service is OK
1 program is dead and /var/run pid file exists
2 program is dead and /var/lock lock file exists
3 program is not running
4 program or service status is unknown
5-99 reserved for future LSB use
100-149 reserved for distribution use
150-199 reserved for application use
200-254 reserved
On Debian, outputs:
"Daemon_name is running.".
"Daemon_name is not running ... failed!"
The pidfile path will be used as argument for pidofproc and must be
provided if the pidfile is not /var/run/$daemon_basename.pid.
status_of_proc can be used to easily implement the "status" argument
of init scripts:
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
- init_is_upstart
If the currently running init daemon is upstart, return zero; if the
calling init script belongs to a package which also provides a native
upstart job, it should generally exit non-zero in this case.
init_is_upstart is available since lsb-base 4.1+Debian3.
To use these functions, source /lib/lsb/init-functions at the
beginning of your (Bourne sh or compatible) init script.
Please depend on lsb-base to ensure all of these functions are available
for your init scripts.
LSB LOGGING FUNCTIONS
This package also includes the LSB-specified logging functions:
log_success_msg message
log_failure_msg message
log_warning_msg message
These functions *do not* comply with Debian policy and should only be used
by LSB packages.
OTHER LSB FUNCTIONALITY
start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args...]
Start "pathname" as a daemon. We call Debian's start-stop-daemon to
implement this functionality.
killproc [-p pidfile] pathname [signal]
Stops "pathname" (using "pidfile", if specified, to find the process
ID). This is implemented using start-stop-daemon as well.
pidofproc [-p pidfile] pathname
Find the process ID of pathname. If the pidfile is specified, we use the
first space-delimited word; otherwise, /bin/pidof is used from the
sysvinit package, if available.
For full documentation, please refer to:
http://refspecs.linuxbase.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptfunc.html
Note: Debian packages probably should use start-stop-daemon directly;
however, these functions may be useful in porting init scripts from
other distributions. Also, if you are developing software for wider
use, you should not expect these functions to be implemented
identically on other LSB-conforming distributions; the only guaranteed
behaviors are those in the specification above.
CUSTOMIZING LOGGING OUTPUT
- FOR PACKAGES AND DISTRIBUTIONS
Since lsb-base 4.1+Debian4, init-functions will source all
correctly-named files under /lib/lsb/init-functions.d for the purpose of
allowing packages to alter or enhance the init-functions functions.
By providing a file in there, any package or derivative distribution can
override the default behaviour of /lib/lsb/init-functions: logging init
script events, changing the logging messages format, etc.
If supplied, these script fragments shall be compatible with any Debian
/bin/sh, as init scripts sourcing /lib/lsb/init-functions may be running
under any Bourne-style shell permitted by Debian policy (i.e. not just
bash).
- FOR ADMINISTRATORS
After those distribution-provided files, if it exists,
/etc/lsb-base-logging.sh will be sourced by /lib/lsb/init-functions.
This file is to be supplied by the administrator for machine-specific
overrides. This file may also be useful on systems where the console log
is not visible during startup.
If supplied, this script fragment should be compatible with any Debian
/bin/sh, as init scripts sourcing this file may be running under any
Bourne-style shell permitted by Debian policy (i.e. not just bash).
- FANCY OUTPUT
"Fancy output" can be overridden by setting FANCYTTY=0 in
/etc/lsb-base-logging.sh .
- OUTPUT FUNCTIONS
From lsb-base 3.2-14, you can use the following hook functions which
are called by the appropriate functions, instead of supplying your own
logging functions:
log_daemon_msg_pre
log_daemon_msg_post
log_begin_msg_pre (since 4.1+Debian1)
log_begin_msg_post (since 4.1+Debian1)
log_action_msg_pre (since 4.1+Debian1)
log_action_msg_post (since 4.1+Debian1)
log_action_begin_msg_pre (since 4.1+Debian1)
log_action_begin_msg_post (since 4.1+Debian1)
log_end_msg_pre
log_end_msg_post
log_action_end_msg_pre
log_action_end_msg_post
Each function receives all of the arguments sent to the parent
function; the "pre" functions operate before any output, while the
"post" functions operate after the output is produced.
FANCY OUTPUT, KNOWN BUGS
* Daemons writing too much information on the screen (hence getting
their output spawned on multiple lines) won't get their [....]
replaced by [ ok ] as the replacement will happen on the last input
line.
* The above has the side-effect of hiding 7 characters of potentially
useful output.
* init.d scripts not using the /lib/lsb/init-functions provided
functions will (obviously) not get the fancy output.
-- Chris Lawrence <lawrencc@debian.org>, Sat, 18 Sep 2010 17:09:57 -0500
-- Didier Raboud <odyx@debian.org> Mon, 21 May 2012 15:00:10 +0200
|