limal-runlevel
Classes | Typedefs | Functions
limal::runlevel Namespace Reference

The LiMaL runlevel library namespace. More...

Classes

class  LSBService
 LSB specific sevice class. More...
class  Service
 Generic service class. More...

Typedefs

typedef BLOCXX_NAMESPACE::Int32 LSBExitCode
 LSB service action exit code type.
typedef BLOCXX_NAMESPACE::Map
< BLOCXX_NAMESPACE::String,
BLOCXX_NAMESPACE::String > 
LSBInitInfo
typedef char Runlevel
typedef
BLOCXX_NAMESPACE::Array
< Runlevel
Runlevels
typedef
BLOCXX_NAMESPACE::Array
< BLOCXX_NAMESPACE::String > 
ServiceCmdArgs
 Shortcut for command argument array.
typedef BLOCXX_NAMESPACE::Map
< BLOCXX_NAMESPACE::String,
BLOCXX_NAMESPACE::String > 
ServiceEnvVars
 Shortcut for environment variable map.

Functions

Runlevel getDefaultRunlevel ()
Runlevel getCurrentRunlevel ()
Runlevels getEnabledRunlevels ()
bool isRunlevelEnabled (Runlevel runlevel)
bool setDefaultRunlevel (Runlevel runlevel)
bool switchToRunlevel (Runlevel runlevel)
BLOCXX_NAMESPACE::Array
< BLOCXX_NAMESPACE::String > 
getRunlevelServiceNames (Runlevel runlevel)
BLOCXX_NAMESPACE::String getServiceScriptDir ()
BLOCXX_NAMESPACE::Array
< BLOCXX_NAMESPACE::String > 
getInstalledServiceNames ()

Variables

Common-Codes

Common LSB exit codes for all actions except "status".

const LSBExitCode LSB_RC_SUCCESS = 0
 success
const LSBExitCode LSB_RC_FAILURE = 1
 generic or unspecified error
const LSBExitCode LSB_RC_INVALID_ARGUMENT = 2
 invalid or excess argument(s)
const LSBExitCode LSB_RC_NOT_IMPLEMENTED = 3
 unimplemented feature ("reload")
const LSBExitCode LSB_RC_NOT_ALLOWED = 4
 user had insufficient privilege
const LSBExitCode LSB_RC_NOT_INSTALLED = 5
 program is not installed
const LSBExitCode LSB_RC_NOT_CONFIGURED = 6
 program is not configured
const LSBExitCode LSB_RC_NOT_RUNNING = 7
 program is not running
Status-Codes

Common LSB exit codes for the "status" action.

const LSBExitCode LSB_ST_RUNNING = 0
 program is running or service is OK
const LSBExitCode LSB_ST_DEAD_PID_EXISTS = 1
 program is dead and /var/run pid file exists
const LSBExitCode LSB_ST_DEAD_LOCK_EXISTS = 2
 program is dead and /var/lock lock file exists
const LSBExitCode LSB_ST_NOT_RUNNING = 3
 program is not running
const LSBExitCode LSB_ST_UNKNOWN = 4
 program or service status is unknown

Detailed Description

The LiMaL runlevel library namespace.

The limal::runlevel namespace is only a alias. The real namespace is defined in the file config.h file to a namespace with appended API version number.


Typedef Documentation

typedef BLOCXX_NAMESPACE::Int32 limal::runlevel::LSBExitCode

LSB service action exit code type.

LSB defines following service action exit codes:

  • In the case of LSB init script action other than "status", the script shall return one of the following exit codes:
    • 0 success
    • 1 generic or unspecified error
    • 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
  • In the case of LSB init script "status" action, the script shall return one of the following exit 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
typedef BLOCXX_NAMESPACE::Map<BLOCXX_NAMESPACE::String, BLOCXX_NAMESPACE::String> limal::runlevel::LSBInitInfo

Runlevel numbers are ascii charactes '0' - '6', 'B' and 'S'.

Linux Standard Base Core Specification 3.0.1 defines the set of valid runlevels 0 - 6, reflecting the most frequent existing practice:

  • 0 System halt
  • 1 Single user mode
  • 2 Local multiuser without remote network
  • 3 Full multiuser with network
  • 4 Not used (reserved for local use)
  • 5 Full multiuser with network and X11 or equivalent
  • 6 System reboot (Do not use this as default runlevel!)
Note:
The meaning of further runlevels is implementation specific.

See the inittab(5) and init(8) manual pages for more information.

The runlevel S is not meant to be used directly. It indicates, that the system is entering single user mode.

The runlevel B is a ondemand entry in the /etc/inittab and can be used to execute processes on demand without to change the runlevel.

On NOVELL / SUSE LINUX, services marked with runlevel B in LSB INIT INFO tags will be executed at system boot.

The runlevels 7 - 9 and the ondemand entries A and C may be also valid, but usually unused.

typedef BLOCXX_NAMESPACE::Array<Runlevel> limal::runlevel::Runlevels
typedef BLOCXX_NAMESPACE::Array<BLOCXX_NAMESPACE::String> limal::runlevel::ServiceCmdArgs

Shortcut for command argument array.

typedef BLOCXX_NAMESPACE::Map<BLOCXX_NAMESPACE::String,BLOCXX_NAMESPACE::String> limal::runlevel::ServiceEnvVars

Shortcut for environment variable map.


Function Documentation

Runlevel limal::runlevel::getCurrentRunlevel ( )
Returns:
Currently active runlevel or -1 on error.
Runlevel limal::runlevel::getDefaultRunlevel ( )
Returns:
Default runlevel as configured in /etc/inittab file or -1 on error.
Runlevels limal::runlevel::getEnabledRunlevels ( )
Returns:
List of runlevels enabled in /etc/inittab.
BLOCXX_NAMESPACE::Array<BLOCXX_NAMESPACE::String> limal::runlevel::getInstalledServiceNames ( )
Returns:
The list of service script names installed in the script path of the current system.
BLOCXX_NAMESPACE::Array<BLOCXX_NAMESPACE::String> limal::runlevel::getRunlevelServiceNames ( Runlevel  runlevel)
Returns:
The list of service script names avaliable (active) for the specified runlevel.
BLOCXX_NAMESPACE::String limal::runlevel::getServiceScriptDir ( )
Returns:
The default service script path of the current system, e.g. "/etc/init.d".
bool limal::runlevel::isRunlevelEnabled ( Runlevel  runlevel)
Parameters:
runlevelThe runlevel to check.
Returns:
True, if the runlevel is enabled.
bool limal::runlevel::setDefaultRunlevel ( Runlevel  runlevel)

Set the default runlevel in /etc/inittab.

Parameters:
runlevelThe new runlevel to set.
Returns:
True on successfull change, false on failure.
bool limal::runlevel::switchToRunlevel ( Runlevel  runlevel)

Trigger a switch to the specified runlevel.

Warning:
e.g. runlevel 0 will halt the system!
Parameters:
runlevelThe new runlevel to switch to.
Returns:
True on successfull request execution, false on failure.

Variable Documentation

const LSBExitCode limal::runlevel::LSB_RC_FAILURE = 1

generic or unspecified error

const LSBExitCode limal::runlevel::LSB_RC_INVALID_ARGUMENT = 2

invalid or excess argument(s)

const LSBExitCode limal::runlevel::LSB_RC_NOT_ALLOWED = 4

user had insufficient privilege

const LSBExitCode limal::runlevel::LSB_RC_NOT_CONFIGURED = 6

program is not configured

const LSBExitCode limal::runlevel::LSB_RC_NOT_IMPLEMENTED = 3

unimplemented feature ("reload")

const LSBExitCode limal::runlevel::LSB_RC_NOT_INSTALLED = 5

program is not installed

const LSBExitCode limal::runlevel::LSB_RC_NOT_RUNNING = 7

program is not running

const LSBExitCode limal::runlevel::LSB_RC_SUCCESS = 0

success

const LSBExitCode limal::runlevel::LSB_ST_DEAD_LOCK_EXISTS = 2

program is dead and /var/lock lock file exists

const LSBExitCode limal::runlevel::LSB_ST_DEAD_PID_EXISTS = 1

program is dead and /var/run pid file exists

const LSBExitCode limal::runlevel::LSB_ST_NOT_RUNNING = 3

program is not running

const LSBExitCode limal::runlevel::LSB_ST_RUNNING = 0

program is running or service is OK

const LSBExitCode limal::runlevel::LSB_ST_UNKNOWN = 4

program or service status is unknown