limal-runlevel
Public Member Functions | Protected Member Functions | Private Attributes

limal::runlevel::LSBService Class Reference

LSB specific sevice class. More...

#include <LSBService.hpp>

Inheritance diagram for limal::runlevel::LSBService:
limal::runlevel::Service

List of all members.

Public Member Functions

 LSBService (const BLOCXX_NAMESPACE::String &name)
 ~LSBService ()
bool isServiceEnabled () const
bool isServiceEnabledInRunlevel (Runlevel runlevel) const
bool enableService () const
bool disableService () const
LSBInitInfo getServiceInitInfo () const
BLOCXX_NAMESPACE::Array
< BLOCXX_NAMESPACE::String > 
getServiceActions () const
BLOCXX_NAMESPACE::Array
< BLOCXX_NAMESPACE::String > 
getDefaultActions () const
LSBExitCode executeAction (const BLOCXX_NAMESPACE::String &action, const ServiceCmdArgs &cmdArgs, BLOCXX_NAMESPACE::String &stdOutput, BLOCXX_NAMESPACE::String &errOutput, const ServiceEnvVars &envVars, const BLOCXX_NAMESPACE::String &stdInput, int timeoutSecs, int outputLimit)
LSBExitCode executeAction (const BLOCXX_NAMESPACE::String &action, const ServiceCmdArgs &cmdArgs)
LSBExitCode executeAction (const BLOCXX_NAMESPACE::String &action)
LSBExitCode executeAction (const BLOCXX_NAMESPACE::String &action, const ServiceCmdArgs &cmdArgs, BLOCXX_NAMESPACE::String &stdOutput, BLOCXX_NAMESPACE::String &errOutput, int &execStatus, const ServiceEnvVars &envVars, const BLOCXX_NAMESPACE::String &stdInput, int timeoutSecs, int outputLimit)
 Deprecated execute the service script action variant.

Protected Member Functions

void addServiceAction (const BLOCXX_NAMESPACE::String &action)

Private Attributes

BLOCXX_NAMESPACE::Array
< BLOCXX_NAMESPACE::String > 
m_actions

Detailed Description

LSB specific sevice class.

This class provides a interface to LSB compliant runlevel scripts.


Constructor & Destructor Documentation

limal::runlevel::LSBService::LSBService ( const BLOCXX_NAMESPACE::String &  name)

Construct a LSBService object using the specified name.

Parameters:
nameThe name of the service or a full path to the script.
Exceptions:
limal::ValueErrorif name is empty or invalid.
limal::runlevel::LSBService::~LSBService ( )

Destructor of LSBService.


Member Function Documentation

void limal::runlevel::LSBService::addServiceAction ( const BLOCXX_NAMESPACE::String &  action) [protected]
bool limal::runlevel::LSBService::disableService ( ) const

Disable the service.

Returns:
true, if the service was sucesfully disabled.
bool limal::runlevel::LSBService::enableService ( ) const

Enable the service using its default runlevel set.

Returns:
true, if the service was sucesfully enabled.
LSBExitCode limal::runlevel::LSBService::executeAction ( const BLOCXX_NAMESPACE::String &  action,
const ServiceCmdArgs cmdArgs,
BLOCXX_NAMESPACE::String &  stdOutput,
BLOCXX_NAMESPACE::String &  errOutput,
int &  execStatus,
const ServiceEnvVars envVars,
const BLOCXX_NAMESPACE::String &  stdInput,
int  timeoutSecs,
int  outputLimit 
)

Deprecated execute the service script action variant.

Deprecated:
This variant is deprecated, because it exposes the non-portable raw exitStatus parameter, that is not avaliable in blocxx 2.x version, where it is always set to -1.
LSBExitCode limal::runlevel::LSBService::executeAction ( const BLOCXX_NAMESPACE::String &  action,
const ServiceCmdArgs cmdArgs,
BLOCXX_NAMESPACE::String &  stdOutput,
BLOCXX_NAMESPACE::String &  errOutput,
const ServiceEnvVars envVars,
const BLOCXX_NAMESPACE::String &  stdInput,
int  timeoutSecs,
int  outputLimit 
)

Execute the service script action.

This method uses the specified additional arguments (the 0th argument is always passed) and execution environment.

The stdout and stderr outputs are gathered into the specified stdOutput and errOutput variables. If the envVars map is empty, the environment of the current process is used.

It returns the LSB exit code returned by the script, if the script terminated normally or -1 in any other case (killed, core dumped).

If a timeout or output limit is reached, the process will be killed and an exception is thrown.

See blocxx::Exec::executeProcessAndGatherOutput() methods documentation for more informations.

Parameters:
actionThe action name (first argument).
cmdArgsAdditional script arguments.
stdOutputString reference for the standard output.
errOutputString reference for the error output.
envVarsThe environment to use (empty for current).
stdInputString with the script input.
timeoutSecsThe number of seconds to wait for the process to exit or -1 to wait infinitely.
outputLimitThe number of bytes that stdOutput or errOutput should not exceed or -1 for unlimited. the process to exit or -1 to wait infinitely.
Returns:
The LSB exit status code or -1 in case that the process was killed or core dumped.
Exceptions:
limal::ValueExceptionon invalid / empty action name.
blocxx::ExecErrorExceptionon execution errors.
blocxx::ExecTimeoutExceptionif the script hasn't finished within timeoutSecs.
blocxx::ExecBufferFullExceptionif the output of the script exceeds the specified outputLimit.
LSBExitCode limal::runlevel::LSBService::executeAction ( const BLOCXX_NAMESPACE::String &  action,
const ServiceCmdArgs cmdArgs 
)

Execute the service script action.

This method discards the output of the script, uses the environment of the current process and supports additional arguments.

Note:
This function may run infinitely if the script never ends.
Parameters:
actionThe action name.
cmdArgsAdditional script arguments.
Returns:
The LSB exit status or -1.
Exceptions:
limal::ValueExceptionon invalid / empty action name.
blocxx::ExecErrorExceptionon execution errors.
LSBExitCode limal::runlevel::LSBService::executeAction ( const BLOCXX_NAMESPACE::String &  action)

Execute the service script action.

This method discards the output of the script and uses the environment of the current process.

Note:
This function may run infinitely if the script never ends.
Parameters:
actionThe action name.
Returns:
The LSB exit status or -1.
Exceptions:
limal::ValueExceptionon invalid / empty action name.
blocxx::ExecErrorExceptionon execution errors.
BLOCXX_NAMESPACE::Array<BLOCXX_NAMESPACE::String> limal::runlevel::LSBService::getDefaultActions ( ) const

Returns array of default LSB action names.

LSB defines in Section 8.2, that the init script actions "start", "stop", "restart", "force-reload" and "status" shall be supported by all init scripts, "try-restart", "reload" and other are optional.

Returns:
The default list of action names for the current system.
BLOCXX_NAMESPACE::Array<BLOCXX_NAMESPACE::String> limal::runlevel::LSBService::getServiceActions ( ) const

Returns known LSB action names.

By default, alias to the getDefaultActionNames() method; may be overiden by a specialized class.

Returns:
Array of known action names.
LSBInitInfo limal::runlevel::LSBService::getServiceInitInfo ( ) const

Returns a LSBInitInfo map containing the service information tags. Leading and trailing spaces in the strings are stripped. The Description field may contain multiple lines, that are separated by
in the map's value string.

Returns:
The INIT INFO tags from service script.
bool limal::runlevel::LSBService::isServiceEnabled ( ) const
Returns:
True, if the service is enabled in any runlevel.
bool limal::runlevel::LSBService::isServiceEnabledInRunlevel ( Runlevel  runlevel) const
Parameters:
runlevelThe runlevel to check for.
Returns:
True, if the service script is enabled (link exists) in the specified runlevel.

Member Data Documentation

BLOCXX_NAMESPACE::Array<BLOCXX_NAMESPACE::String> limal::runlevel::LSBService::m_actions [private]

The documentation for this class was generated from the following file: