Linux Standard Base Core Specification 3.0Preview1 | ||
---|---|---|
<<< Previous | Chapter 8. System Initialization | Next >>> |
Init files provided by LSB applications shall accept one argument, saying what to do:
start | start the service |
stop | stop the service |
restart | stop and restart the service if the service is already running, otherwise start the service |
try-restart | restart the service if the service is already running |
reload | cause the configuration of the service to be reloaded without actually stopping and restarting the service |
force-reload | cause the configuration to be reloaded if the service supports this, otherwise restart the service if it is running |
status | print the current status of the service |
The start, stop, restart, force-reload, and status commands shall be supported by all init files; the reload and the try-restart options are optional. Other init script actions may be defined by the init script.
Init files shall ensure that they will behave sensibly if invoked with start when the service is already running, or with stop when it isn't, and that they don't kill unfortunately-named user processes. The best way to achieve this is to use the init-script functions provided by /lib/lsb/init-functions.
If a service reloads its configuration automatically (as in the case of cron, for example), the reload option of the init file shall behave as if the configuration has been reloaded successfully. The restart, try-restart, reload and force-reload action may be atomic; i.e. if a service is known not be operational after a restart or reload, the script may return an error without any further action.
These executable files shall not fail obscurely when the configuration files remain but the package has been removed, as the default in [the packaging system] is to leave configuration files on the system after the package has been removed. Only when it is executed with the [purge] option will [the packaging system] remove configuration files. Therefore, you should include a test statement at the top of the file, like this:
test -f program-executed-later-in-file || exit 5 |
If the status command is given, the init script will return the following exit status codes.
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 |
In the case of init script commands other than "status" (i.e., "start", "stop", "restart", "try-restart", "reload", and "force-reload"), the init script shall return an exit status of zero if the action described by the argument has been successful. Otherwise, the exit status shall be non-zero, as defined below. In addition to straightforward success, the following situations are also to be considered successful:
restarting a service (instead of reloading it) with the "force-reload" argument
running "start" on a service already running
running "stop" on a service already stopped or not running
running "restart" on a service already stopped or not running
running "try-restart" on a service already stopped or not running
In case of an error, while processing any init script action except for "status", the init script shall print an error message and return one of the following non-zero exit status codes.
1 | generic or unspecified error (current practice) |
2 | invalid or excess argument(s) |
3 | unimplemented feature (for example, "reload") |
4 | user had insufficient privilege |
5 | program is not installed |
6 | program is not configured |
7 | program is not running |
8-99 | reserved for future LSB use |
100-149 | reserved for distribution use |
150-199 | reserved for application use |
200-254 | reserved |
Error and status messages should be printed with the logging functions such as log_failure_msg and so on. Scripts may write to standard error or standard output, but implementations need not present text written to standard error/output to the user or do anything else with it.
Since init files may be run manually by a system administrator with non-standard environment variable values for PATH, USER, LOGNAME, etc. init files shall not depend on the values of these environment variables. They should set them to some known/default values if they are needed.
<<< Previous | Home | Next >>> |
System Initialization | Up | Comment Conventions for Init Scripts |