2009-02-13 Ramon Novoa <rnovoa@artica.es>

* windows/pandora_wmi.cc
          windows/pandora_wmi.h
          modules/pandora_module_exec.cc: Hide console window when executing
          exec modules.

        * modules/pandora_module_proc.cc,
          modules/pandora_module_proc.h,
          modules/pandora_module_factory.cc: Added module_retries,
          module_startdelay and module_retrydelay options to proc
          modules.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1454 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2009-02-13 14:34:10 +00:00
parent b241562a35
commit e5a65eda12
5 changed files with 101 additions and 8 deletions

View File

@ -1,3 +1,16 @@
2009-02-13 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc
windows/pandora_wmi.h
modules/pandora_module_exec.cc: Hide console window when executing
exec modules.
* modules/pandora_module_proc.cc,
modules/pandora_module_proc.h,
modules/pandora_module_factory.cc: Added module_retries,
module_startdelay and module_retrydelay options to proc
modules.
2009-02-12 Esteban Sanchez <estebans@artica.es>
* main.cc: Added new parameter to help text.

View File

@ -106,7 +106,7 @@ Pandora_Module_Exec::run () {
/* Create the child process. */
if (! CreateProcess (NULL, (CHAR *) this->module_exec.c_str (), NULL,
NULL, TRUE, CREATE_SUSPENDED, NULL,
NULL, TRUE, CREATE_SUSPENDED | CREATE_NO_WINDOW, NULL,
working_dir.c_str (), &si, &pi)) {
pandoraLog ("Pandora_Module_Exec: %s CreateProcess failed. Err: %d",
this->module_name.c_str (), GetLastError ());

View File

@ -60,6 +60,9 @@ using namespace Pandora_Strutils;
#define TOKEN_START_COMMAND ("module_start_command ")
#define TOKEN_WMIQUERY ("module_wmiquery ")
#define TOKEN_WMICOLUMN ("module_wmicolumn ")
#define TOKEN_RETRIES ("module_retries ")
#define TOKEN_STARTDELAY ("module_startdelay ")
#define TOKEN_RETRYDELAY ("module_retrydelay ")
string
parseLine (string line, string token) {
@ -124,6 +127,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
module_start_command = "";
module_wmiquery = "";
module_wmicolumn = "";
module_retries = "";
module_startdelay = "";
module_retrydelay = "";
stringtok (tokens, definition, "\n");
@ -206,6 +212,15 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
if (module_wmicolumn == "") {
module_wmicolumn = parseLine (line, TOKEN_WMICOLUMN);
}
if (module_retries == "") {
module_retries = parseLine (line, TOKEN_RETRIES);
}
if (module_startdelay == "") {
module_startdelay = parseLine (line, TOKEN_STARTDELAY);
}
if (module_retrydelay == "") {
module_retrydelay = parseLine (line, TOKEN_RETRYDELAY);
}
iter++;
}
@ -235,6 +250,9 @@ Pandora_Module_Factory::getModuleFromDefinition (string definition) {
module_proc = (Pandora_Module_Proc *) module;
module_proc->setWatchdog (true);
module_proc->setStartCommand (module_start_command);
module_proc->setRetries (atoi(module_retries));
module_proc->setStartDelay (atoi(module_startdelay));
module_proc->setRetryDelay (atoi(module_retrydelay));
}
}
} else if (module_service != "") {

View File

@ -49,6 +49,9 @@ Pandora_Module_Proc::Pandora_Module_Proc (string name, string process_name)
this->watchdog = false;
this->start_command = "";
this->retries = INT_MAX;
this->start_delay = MIN_DELAY;
this->retry_delay = MIN_DELAY;
}
string
@ -66,6 +69,21 @@ Pandora_Module_Proc::getStartCommand () const {
return this->start_command;
}
int
Pandora_Module_Proc::getRetries () const {
return this->retries;
}
int
Pandora_Module_Proc::getStartDelay () const {
return this->start_delay;
}
int
Pandora_Module_Proc::getStopDelay () const {
return this->stop_delay;
}
void
Pandora_Module_Proc::setWatchdog (bool watchdog) {
this->watchdog = watchdog;
@ -76,6 +94,30 @@ Pandora_Module_Proc::setStartCommand (string command) {
this->start_command = command;
}
void
Pandora_Module_Proc::setRetries (int retries) {
if (retries < 1) {
return;
}
this->retries = retries;
}
void
Pandora_Module_Proc::setStartDelay (int mseconds) {
if (mseconds < MIN_DELAY) {
return;
}
this->start_delay = start_delay;
}
void
Pandora_Module_Proc::setRetryDelay (int mseconds) {
if (mseconds < MIN_DELAY) {
return;
}
this->retry_delay = retry_delay;
}
void
async_run (Pandora_Module_Proc *module) {
HANDLE *processes = NULL;
@ -84,24 +126,31 @@ async_run (Pandora_Module_Proc *module) {
Pandora_Module_List *modules;
string str_res;
string prev_res;
int res;
int i;
int i, res, counter = 0;
prev_res = module->getLatestOutput ();
modules = new Pandora_Module_List ();
modules->addModule (module);
Sleep (2000);
Sleep (this->getStartDelay ());
while (1) {
processes = getProcessHandles (module->getProcessName ());
if (processes == NULL) {
if (module->isWatchdog ()) {
Pandora_Wmi::runProgram (module->getStartCommand ());
if (counter >= this->getRetries ()) {
this->setWatchdog (false);
} else {
Pandora_Wmi::runProgram (module->getStartCommand ());
counter++;
}
}
Sleep (2000);
Sleep (this->getStartDelay ());
continue;
}
/* Reset retries counter */
counter = 0;
/* There are opened processes */
res = Pandora_Wmi::isProcessRunning (module->getProcessName ());
str_res = inttostr (res);
@ -136,6 +185,8 @@ async_run (Pandora_Module_Proc *module) {
for (i = 0; i < nprocess; i++)
CloseHandle (processes[i]);
pandoraFree (processes);
Sleep (this->getRetryDelay ());
}
delete modules;

View File

@ -23,6 +23,8 @@
#include "pandora_module.h"
#define MIN_DELAY 2000 /* Minimum process start/retry delay */
namespace Pandora_Modules {
/**
* Module to check that a process is running on the system.
@ -33,15 +35,24 @@ namespace Pandora_Modules {
HANDLE thread;
bool watchdog;
string start_command;
int retries;
int start_delay;
int stop_delay;
public:
Pandora_Module_Proc (string name, string process_name);
string getProcessName () const;
string getStartCommand () const;
bool isWatchdog () const;
bool isWatchdog () const;
int getRetries () const;
int getStartDelay () const;
void getRetryDelay () const;
void setWatchdog (bool watchdog);
void setStartCommand (string command);
void setStartCommand (string command);
void setRetries (int retries);
void setStartDelay (int mseconds);
void setRetryDelay (int mseconds);
void run ();
};