Generic service class.
More...
#include <Service.hpp>
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:
-
name | The name of the service or a full path to the script. |
- Exceptions:
-
limal::ValueError | if name is empty or invalid. |
limal::runlevel::Service::~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:
-
cmdArgs | Additional script arguments. |
stdOutput | String reference for the standard output. |
errOutput | String reference for the error output. |
envVars | The environment to use (empty for current). |
stdInput | String with the script input. |
timeoutSecs | The number of seconds to wait for the process to exit or -1 to wait infinitely. |
outputLimit | The 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::ExecErrorException | on execution errors. |
blocxx::ExecTimeoutException | if the script hasn't finished within timeoutSecs. |
blocxx::ExecBufferFullException | if 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:
-
cmdArgs | Additional script arguments. |
- Returns:
- The process exit status or -1 on failure.
- Exceptions:
-
blocxx::ExecErrorException | on 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:
-
name | The name of the service or a full path to the script. |
- Exceptions:
-
limal::ValueError | if name is empty or invalid. |
Member Data Documentation
The documentation for this class was generated from the following file: