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

limal::runlevel::Service Class Reference

Generic service class. More...

#include <Service.hpp>

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

List of all members.

Public Member Functions

 Service (const BLOCXX_NAMESPACE::String &name)
 ~Service ()
BLOCXX_NAMESPACE::String getServiceName () const
BLOCXX_NAMESPACE::String getScriptPath () const
BLOCXX_NAMESPACE::String getScriptName () const
bool isServiceInstalled () const
int executeScript (const ServiceCmdArgs &cmdArgs, BLOCXX_NAMESPACE::String &stdOutput, BLOCXX_NAMESPACE::String &errOutput, const ServiceEnvVars &envVars, const BLOCXX_NAMESPACE::String &stdInput, int timeoutSecs, int outputLimit)
int executeScript (const ServiceCmdArgs &cmdArgs)
int executeScript (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 variant.

Protected Member Functions

void setScriptName (const BLOCXX_NAMESPACE::String &name)

Private Member Functions

 Service ()

Private Attributes

BLOCXX_NAMESPACE::String m_path
BLOCXX_NAMESPACE::String m_name

Detailed Description

Generic service class.

This class provides a generic interface to service scripts.


Constructor & Destructor Documentation

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

Construct a Service 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::Service::~Service ( )

Destructor of Service.

limal::runlevel::Service::Service ( ) [private]

Member Function Documentation

int limal::runlevel::Service::executeScript ( 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.

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 exit status of the script process, 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:
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 exit status of the process or -1 in case that the process was killed or core dumped.
Exceptions:
blocxx::ExecErrorExceptionon execution errors.
blocxx::ExecTimeoutExceptionif the script hasn't finished within timeoutSecs.
blocxx::ExecBufferFullExceptionif the output of the script exceeds the specified outputLimit.
int limal::runlevel::Service::executeScript ( const ServiceCmdArgs cmdArgs)

Execute the service script.

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:
cmdArgsAdditional script arguments.
Returns:
The process exit status or -1 on failure.
Exceptions:
blocxx::ExecErrorExceptionon execution errors.
int limal::runlevel::Service::executeScript ( 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 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.
BLOCXX_NAMESPACE::String limal::runlevel::Service::getScriptName ( ) const
Returns:
Full path to the script file name.
BLOCXX_NAMESPACE::String limal::runlevel::Service::getScriptPath ( ) const
Returns:
The service script directory name.
BLOCXX_NAMESPACE::String limal::runlevel::Service::getServiceName ( ) const
Returns:
The short name of the service.
bool limal::runlevel::Service::isServiceInstalled ( ) const
Returns:
True, if the service script exists in the system service directory.
void limal::runlevel::Service::setScriptName ( const BLOCXX_NAMESPACE::String &  name) [protected]

Set the service name and optionally the script path.

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

Member Data Documentation

BLOCXX_NAMESPACE::String limal::runlevel::Service::m_name [private]
BLOCXX_NAMESPACE::String limal::runlevel::Service::m_path [private]

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