Init Script Actions

Init files should accept one argument, saying what to do:

startstart the service
stopstop the service
restartstop and restart the service if the service is already running, otherwise start the service
reloadcause the configuration of the service to be reloaded without actually stopping and restarting the service
force-reloadcause the configuration to be reloaded if the service supports this, otherwise restart the service
statusprint the current status of the service

The start, stop, restart, force-reload, and status options must be supported by all init files, the reload option is optional.

Init files should 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 usually to use start-stop-daemon [1] .

If a service reloads its configuration automatically (as in the case of cron, for example), the reload option of the init file should behave as if the configuration has been reloaded successfully.

These executable files should 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
or take the equivalent action if the init file is not a shell script.

Init files should return an exit status of zero if the action described by the argument has been successful. Otherwise, the exit status should be non-zero. In addition to straightforward success, the following situations are also to be considered successful:

Exit status for "status" command:

0program is running
1program is dead and /var/run pid file exists
2program is dead and /var/lock lock file exists
3program is stopped
4-100reserved for future LSB use
100-149reserved for distribution use
150-199reserved for application use
200-254reserved

Exit status for "start", "stop", "restart", "reload", and "force-reload":

In error conditions, the init file should fail, print an error, and return one of the following non-zero exit status codes.

1generic or unspecified error (current practice)
2invalid or excess argument(s)
3unimplemented feature (for example, "reload")
4user had insufficient privilege
5program is not installed
6program is not configured
7program is not running
8-100reserved for future LSB use
100-149reserved for distribution use
150-199reserved for application use
200-254reserved

All error messages should be printed on standard error. All status messages should be printed on standard output.

Since init files may be run manually by a system administrator with non-standard environment variable values for PATH, USER, LOGNAME, etc. init files should not depend on the values of these environment variables. They should set them to some known/default values if they are needed.

Notes

[1]

assuming that start-stop-daemon or a similar program is included in the LSB