2009-10-15 Ramon Novoa <rnovoa@artica.es>

* windows_service.cc: Enable service recovery by default.

        * pandora_windows_service.cc: Added autotime, group and description
          configuration options.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2024 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2009-10-15 14:30:38 +00:00
parent 0c02bda5ec
commit 472af37ca9
3 changed files with 39 additions and 4 deletions

View File

@ -1,3 +1,10 @@
2009-10-15 Ramon Novoa <rnovoa@artica.es>
* windows_service.cc: Enable service recovery by default.
* pandora_windows_service.cc: Added autotime, group and description
configuration options.
2009-10-13 Sancho Lerena <slerena@artica.es>
* bin/PandoraAgent.exe: Last build of agent binary.

View File

@ -189,17 +189,23 @@ Pandora_Windows_Service::getXmlHeader () {
}
agent->SetAttribute ("agent_name", value);
value = conf->getValue ("description");
agent->SetAttribute ("description", value);
agent->SetAttribute ("version", getPandoraAgentVersion ());
// Get current time
ctime = time(0);
ctime_tm = localtime(&ctime);
sprintf (timestamp, "%d-%02d-%02d %02d:%02d:%02d", ctime_tm->tm_year + 1900,
ctime_tm->tm_mon + 1, ctime_tm->tm_mday, ctime_tm->tm_hour,
ctime_tm->tm_min, ctime_tm->tm_sec);
value = conf->getValue ("autotime");
if (value != "1") {
sprintf (timestamp, "%d-%02d-%02d %02d:%02d:%02d", ctime_tm->tm_year + 1900,
ctime_tm->tm_mon + 1, ctime_tm->tm_mday, ctime_tm->tm_hour,
ctime_tm->tm_min, ctime_tm->tm_sec);
agent->SetAttribute ("timestamp", timestamp);
agent->SetAttribute ("timestamp", timestamp);
}
value = conf->getValue ("interval");
agent->SetAttribute ("interval", value);
@ -210,6 +216,9 @@ Pandora_Windows_Service::getXmlHeader () {
value = value + Pandora_Windows_Info::getOSVersion ();
agent->SetAttribute ("os_version", value);
value = conf->getValue ("group");
agent->SetAttribute ("group", value);
return agent;
}

View File

@ -165,6 +165,8 @@ void
Windows_Service::install (LPCTSTR application_binary_path) {
SC_HANDLE sc_manager;
SERVICE_DESCRIPTION sd_buf;
SERVICE_FAILURE_ACTIONS fa;
SC_ACTION sa[2];
cout << " [SERVICE] Attempting to install the service.\n";
cout << " [SERVICE] The full path to the binary is: " << application_binary_path << endl;
@ -276,6 +278,23 @@ Windows_Service::install (LPCTSTR application_binary_path) {
cout << " [SERVICE] Unable to add a description to the service. " << msg << endl;
}
/* Enable service recovery */
fa.dwResetPeriod = 86400; // One day
fa.lpRebootMsg = NULL;
fa.lpCommand = NULL;
fa.cActions = 2;
sa[0].Delay = 300000; // One minute
sa[0].Type = SC_ACTION_RESTART;
sa[1].Delay = 0;
sa[1].Type = SC_ACTION_NONE;
fa.lpsaActions = sa;
if (!ChangeServiceConfig2 (sc_service, SERVICE_CONFIG_FAILURE_ACTIONS, &fa)) {
TCHAR msg[1000];
svc_format_message (msg, sizeof (msg));
cout << " [SERVICE] Service recovery could not be enabled. " << msg << endl;
}
cout << " [SERVICE] Successfully added the service to the Services database." << endl;
CloseServiceHandle (sc_service);