diff --git a/pandora_agents/win32/ChangeLog b/pandora_agents/win32/ChangeLog index 241955243e..31e1d62ea2 100644 --- a/pandora_agents/win32/ChangeLog +++ b/pandora_agents/win32/ChangeLog @@ -1,3 +1,10 @@ +2009-10-15 Ramon Novoa + + * windows_service.cc: Enable service recovery by default. + + * pandora_windows_service.cc: Added autotime, group and description + configuration options. + 2009-10-13 Sancho Lerena * bin/PandoraAgent.exe: Last build of agent binary. diff --git a/pandora_agents/win32/pandora_windows_service.cc b/pandora_agents/win32/pandora_windows_service.cc index 6364affc78..0fac342235 100644 --- a/pandora_agents/win32/pandora_windows_service.cc +++ b/pandora_agents/win32/pandora_windows_service.cc @@ -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; } diff --git a/pandora_agents/win32/windows_service.cc b/pandora_agents/win32/windows_service.cc index 1bdc853a08..cd601eec07 100644 --- a/pandora_agents/win32/windows_service.cc +++ b/pandora_agents/win32/windows_service.cc @@ -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);