14.8. Init Script Functions

Each LSB-compliant init.d script shall source the file /lib/lsb/init-functions. This file shall cause the following shell script commands to be defined. This can be done either by adding a directory to the PATH variable which defines these commands, or by defining sh aliases. While the distribution-provided aliases may choose to use shell extensions (at the distribution's option), the LSB init.d files themselves should only depend in shell features as defined by the LSB.

The start_daemon, killproc and pidofproc functions shall use this algorithm for determining the status and the pid(s) of the specified program. They shall read the pidfile specified or otherwise /var/run/basename.pid and use the pid(s) herein when determining whether a program is running. The method used to determine the status is implementation defined, but should allow for non-binary programs.

Note: Commonly used methods check either for the existence of the /proc/pid directory or use /proc/pid/exe and /proc/pid/cmdline. Relying only on /proc/pid/exe is discouraged since this results in a not-running status for daemons that are written in a script language.

Compliant implementations may use other mechanisms besides those based on pidfiles, unless the -p pidfile option has been used. Compliant applications should not rely on such mechanisms and should always use a pidfile. When a program is stopped, it should delete its pidfile. Multiple pid(s) shall be separated by a single space in the pidfile and in the output of pidofproc.

start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args]This runs the specified program as a daemon. start_daemon shall check if the program is already running using the algorithm given above. If so, it shall not start another copy of the daemon unless the -f option is given. The -n option specifies a nice level. See nice(1). start_daemon should return the LSB defined exit status codes. It shall return 0 if the program has been successfully started or is running and not 0 otherwise.
killproc [-p pidfile] pathname [signal]This stops the specified program. The program is found using the algorithm given above. If a signal is specified, using the -signal_name or -signal_number syntaxes as specified by the kill command, the program is sent that signal. Otherwise, a SIGTERM followed by a SIGKILL after some number of seconds shall be sent. If a program has been terminated, the pidfile should be removed if the terminated process has not already done so. Compliant applications may use the basename instead of the pathname. killproc should return the LSB defined exit status codes. If called without a signal, it shall return 0 if the program has been stopped or is not running and not 0 otherwise. If a signal is given, it shall return 0 only if the program is running.
pidofproc [-p pidfile] pathnameThis function returns one or more pid(s) for a particular daemon using the algorithm given above. Only pids of running processes should be returned. Compliant applications may use the basename instead of the pathname. pidofproc should return the LSB defined exit status codes for "status". It shall return 0 if the program is running and not 0 otherwise.
log_success_msg "message"This requests the distribution to print a success message. The message should be relatively short; no more than 60 characters is highly desirable.
log_failure_msg "message"This requests the distribution to print a failure message. The message should be relatively short; no more than 60 characters is highly desirable.
log_warning_msg "message"This requests the distribution to print a warning message. The message should be relatively short; no more than 60 characters is highly desirable.