mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
Merge branch 'ent-1371-no-estan-funcionando-los-watchdog-de-servicios-windows' into 'develop'
Ent 1371 no estan funcionando los watchdog de servicios windows See merge request !867
This commit is contained in:
commit
6471144cfb
@ -20,12 +20,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "pandora_module_service.h"
|
#include "pandora_module_service.h"
|
||||||
#include "pandora_module_list.h"
|
|
||||||
#include "../windows/pandora_wmi.h"
|
#include "../windows/pandora_wmi.h"
|
||||||
#include "../pandora_strutils.h"
|
#include "../pandora_strutils.h"
|
||||||
#include "../pandora_windows_service.h"
|
#include "../pandora_windows_service.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
using namespace Pandora;
|
using namespace Pandora;
|
||||||
using namespace Pandora_Modules;
|
using namespace Pandora_Modules;
|
||||||
@ -83,8 +83,6 @@ async_run (Pandora_Module_Service *module) {
|
|||||||
HANDLE event_log;
|
HANDLE event_log;
|
||||||
HANDLE event;
|
HANDLE event;
|
||||||
DWORD result;
|
DWORD result;
|
||||||
int res;
|
|
||||||
string str_res;
|
|
||||||
BYTE buffer[BUFFER_SIZE];
|
BYTE buffer[BUFFER_SIZE];
|
||||||
EVENTLOGRECORD *record;
|
EVENTLOGRECORD *record;
|
||||||
DWORD read;
|
DWORD read;
|
||||||
@ -93,10 +91,20 @@ async_run (Pandora_Module_Service *module) {
|
|||||||
bool service_event;
|
bool service_event;
|
||||||
string prev_res;
|
string prev_res;
|
||||||
Pandora_Module_List *modules;
|
Pandora_Module_List *modules;
|
||||||
|
bool polling;
|
||||||
|
|
||||||
prev_res = module->getLatestOutput ();
|
prev_res = module->getLatestOutput ();
|
||||||
modules = new Pandora_Module_List ();
|
modules = new Pandora_Module_List ();
|
||||||
modules->addModule (module);
|
modules->addModule (module);
|
||||||
|
|
||||||
|
struct stat st;
|
||||||
|
// Use polling if there is not local politics and events
|
||||||
|
// do not emit logs. It is a way to check if there is a
|
||||||
|
// Home Edition Windows distribution
|
||||||
|
polling = (stat("C:\\Windows\\System32\\gpedit.msc", &st) != 0);
|
||||||
|
if (polling) {
|
||||||
|
pandoraLog("Async polling service %s for this Windows edition", module->getServiceName().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
event_log = OpenEventLog (NULL, "Service Control Manager");
|
event_log = OpenEventLog (NULL, "Service Control Manager");
|
||||||
@ -113,6 +121,12 @@ async_run (Pandora_Module_Service *module) {
|
|||||||
if (result != WAIT_OBJECT_0) {
|
if (result != WAIT_OBJECT_0) {
|
||||||
CloseHandle (event);
|
CloseHandle (event);
|
||||||
CloseEventLog (event_log);
|
CloseEventLog (event_log);
|
||||||
|
// If time out and polling,
|
||||||
|
// check the service status actively
|
||||||
|
if (result == WAIT_TIMEOUT && polling) {
|
||||||
|
pandoraLog("Timeout. Polling");
|
||||||
|
module->execute_async_service(prev_res, module, modules);
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,17 +152,7 @@ async_run (Pandora_Module_Service *module) {
|
|||||||
|
|
||||||
/* A start/stop action was thrown */
|
/* A start/stop action was thrown */
|
||||||
if (service_event) {
|
if (service_event) {
|
||||||
res = Pandora_Wmi::isServiceRunning (module->getServiceName ());
|
module->execute_async_service(prev_res, module, modules);
|
||||||
str_res = inttostr (res);
|
|
||||||
if (str_res != prev_res) {
|
|
||||||
module->setOutput (str_res);
|
|
||||||
prev_res = str_res;
|
|
||||||
Pandora_Windows_Service::getInstance ()->sendXml (modules);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res == 0 && module->isWatchdog ()) {
|
|
||||||
Pandora_Wmi::startService (module->getServiceName ());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
CloseHandle (event);
|
CloseHandle (event);
|
||||||
CloseEventLog (event_log);
|
CloseEventLog (event_log);
|
||||||
@ -156,6 +160,31 @@ async_run (Pandora_Module_Service *module) {
|
|||||||
delete modules;
|
delete modules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Execute the service async task
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
Pandora_Module_Service::execute_async_service(
|
||||||
|
string &prev_res, Pandora_Module_Service *module, Pandora_Module_List *modules
|
||||||
|
) {
|
||||||
|
string str_res;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
res = Pandora_Wmi::isServiceRunning (module->getServiceName ());
|
||||||
|
str_res = inttostr (res);
|
||||||
|
if (str_res != prev_res) {
|
||||||
|
module->setOutput (str_res);
|
||||||
|
prev_res = str_res;
|
||||||
|
Pandora_Windows_Service::getInstance ()->sendXml (modules);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (res == 0 && module->isWatchdog ()) {
|
||||||
|
pandoraLog("Starting service");
|
||||||
|
Pandora_Wmi::startService (module->getServiceName ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Pandora_Module_Service::run () {
|
Pandora_Module_Service::run () {
|
||||||
int res;
|
int res;
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#define __PANDORA_MODULE_SERVICE_H__
|
#define __PANDORA_MODULE_SERVICE_H__
|
||||||
|
|
||||||
#include "pandora_module.h"
|
#include "pandora_module.h"
|
||||||
|
#include "pandora_module_list.h"
|
||||||
|
|
||||||
namespace Pandora_Modules {
|
namespace Pandora_Modules {
|
||||||
/**
|
/**
|
||||||
@ -41,6 +42,7 @@ namespace Pandora_Modules {
|
|||||||
void run ();
|
void run ();
|
||||||
string getServiceName () const;
|
string getServiceName () const;
|
||||||
bool isWatchdog () const;
|
bool isWatchdog () const;
|
||||||
|
void execute_async_service (string &prev_res, Pandora_Module_Service *module, Pandora_Module_List *modules);
|
||||||
|
|
||||||
void setWatchdog (bool watchdog);
|
void setWatchdog (bool watchdog);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user