Module: check_mk
Branch: master
Commit: 68999dfa1aa144059cf13e9f47045b05c5b357f7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=68999dfa1aa144…
Author: Sebastian Herbord <sh(a)mathias-kettner.de>
Date: Fri Apr 8 11:44:32 2016 +0200
3117 FIX windows agent: fixed installer may fail to re-start service on update
When updating the agent (i.e. through the auto updater) there was only a fairly short
timeout for
the agent-service to stop.
If the agent failed to stop in time (i.e. because of a long-running plugin) the agent was
still
installed but the service wasn't started afterwards.
This has now been fixed by enforcing an unlimited wait when the service is being shut
down.
---
.werks/3117 | 14 ++++++++++++++
ChangeLog | 1 +
agents/windows/check_mk_agent.cc | 29 +++++++++++++++++++++++++++++
3 files changed, 44 insertions(+)
diff --git a/.werks/3117 b/.werks/3117
new file mode 100644
index 0000000..9d71fed
--- /dev/null
+++ b/.werks/3117
@@ -0,0 +1,14 @@
+Title: windows agent: fixed installer may fail to re-start service on update
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.9i1
+Date: 1460108180
+
+When updating the agent (i.e. through the auto updater) there was only a fairly short
timeout for
+the agent-service to stop.
+If the agent failed to stop in time (i.e. because of a long-running plugin) the agent was
still
+installed but the service wasn't started afterwards.
+This has now been fixed by enforcing an unlimited wait when the service is being shut
down.
diff --git a/ChangeLog b/ChangeLog
index 087fa9c..118acca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -135,6 +135,7 @@
* 3368 FIX: Fixed regression since 1.2.8b9 which broke all SNMP checks with Nagios
core
* 3370 FIX: check_mail: Fixed mail parsing bug when using POP3
* 3372 FIX: check_mailboxes: Improved error handling
+ * 3117 FIX: windows agent: fixed installer may fail to re-start service on update...
Multisite:
* 3187 notification view: new filter for log command via regex
diff --git a/agents/windows/check_mk_agent.cc b/agents/windows/check_mk_agent.cc
index 471491c..5e18b11 100644
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -277,6 +277,13 @@ void debug_script_container(script_container *container) {
crash_log("buffer_work: \n<<<<\n%s\n>>>>",
container->buffer_work);
}
+
+template <typename T>
+bool in_set(const T &val, const std::set<T> &test_set) {
+ return test_set.find(val) != test_set.end();
+}
+
+
// .----------------------------------------------------------------------.
// | ______ _ _ _ ______ |
// | / / / /___ _ _ ___| |_ ___ _ __ ___ | |_(_)_ __ ___ ___\ \ \ \ |
@@ -2708,6 +2715,28 @@ void UninstallService() {
if (service) {
SERVICE_STATUS serviceStatus;
if (QueryServiceStatus(service, &serviceStatus)) {
+ while (in_set(serviceStatus.dwCurrentState,
+ {SERVICE_RUNNING, SERVICE_STOP_PENDING})) {
+ if (serviceStatus.dwCurrentState == SERVICE_STOP_PENDING) {
+ printf(SERVICE_NAME " waiting for service to
finish\n");
+ // wait for the wait-hint but no less than 1 second and
+ // no more than 10
+ DWORD waitTime = serviceStatus.dwWaitHint / 10;
+ waitTime =
+ std::max(1000UL, std::min(waitTime, 10000UL));
+ Sleep(waitTime);
+ if (!QueryServiceStatus(service, &serviceStatus)) {
+ break;
+ }
+ } else {
+ if (ControlService(service, SERVICE_CONTROL_STOP,
+ &serviceStatus) == 0) {
+ break;
+ }
+ printf(SERVICE_NAME " stopped\n");
+ }
+ }
+
if (serviceStatus.dwCurrentState == SERVICE_STOPPED) {
if (DeleteService(service))
printf(SERVICE_NAME " Removed Successfully\n");