Author: mladen.turk(a)jboss.com
Date: 2013-01-04 05:25:51 -0500 (Fri, 04 Jan 2013)
New Revision: 2980
Modified:
trunk/utils/windows/native/service/jbosssvc/jboss.c
trunk/utils/windows/native/service/jbosssvc/jboss.manifest
trunk/utils/windows/native/service/jbosssvc/jboss.rc
Log:
Make sure shutdown has timeout as well
Modified: trunk/utils/windows/native/service/jbosssvc/jboss.c
===================================================================
--- trunk/utils/windows/native/service/jbosssvc/jboss.c 2013-01-03 01:27:44 UTC (rev
2979)
+++ trunk/utils/windows/native/service/jbosssvc/jboss.c 2013-01-04 10:25:51 UTC (rev
2980)
@@ -1,7 +1,7 @@
/*
* JBOSSSVC - JBoss Service helper
*
- * Copyright(c) 2012 Red Hat Inc.,
+ * Copyright(c) 2013 Red Hat Inc.,
* and individual contributors as indicated by the @authors tag.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
@@ -636,11 +636,11 @@
if (dwCurrentState == SERVICE_START_PENDING)
_service_status.dwControlsAccepted = 0;
else
- _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
+ _service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP |
SERVICE_ACCEPT_SHUTDOWN;
_service_status.dwCurrentState = dwCurrentState;
_service_status.dwWin32ExitCode = dwWin32ExitCode;
- _service_status.dwWaitHint = dwWaitHint;
+ _service_status.dwWaitHint = dwWaitHint * 1000;
if ((dwCurrentState == SERVICE_RUNNING) ||
(dwCurrentState == SERVICE_STOPPED))
@@ -710,10 +710,6 @@
} while (Process32Next(hProcessSnap, &pe32));
CloseHandle(hProcessSnap);
- if (WaitForSingleObject(_service_run_event, 2000) == WAIT_TIMEOUT) {
- if (_service_run_hproc != NULL)
- return TerminateProcess(_service_run_hproc, retCode);
- }
return TRUE;
}
@@ -730,24 +726,29 @@
BuildCommandLine(cmd, "stop");
AddToMessageLog(FALSE, "Stopping service %s", _service_name);
-
ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, _service_shtm);
if (RunChildProcess(_cmd_exe, cmd, &prInfo)) {
- WaitForSingleObject(prInfo.hProcess, INFINITE);
- AddToMessageLog(FALSE, "Stopped service %s", _service_name);
+ if (WaitForSingleObject(prInfo.hProcess, _service_shtm * 1000) == WAIT_OBJECT_0)
+ AddToMessageLog(FALSE, "Service stop executed %s", _service_name);
+ else
+ TerminateProcessGroup(prInfo.dwProcessId, 1);
CloseHandle(prInfo.hProcess);
CloseHandle(prInfo.hThread);
- ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
- if (WaitForSingleObject(_service_run_event, _service_shtm * 1000) ==
WAIT_TIMEOUT) {
- ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
+ ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, _service_shtm);
+ if (WaitForSingleObject(_service_run_event, _service_shtm * 1000) !=
WAIT_OBJECT_0) {
+ ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 2);
TerminateProcessGroup(_service_run_pid, 1);
+ if (WaitForSingleObject(_service_run_event, 2000) != WAIT_OBJECT_0) {
+ if (_service_run_hproc != NULL)
+ TerminateProcess(_service_run_hproc, 1);
+ }
AddToMessageLog(FALSE, "Service forcibly terminated %s",
_service_name);
}
}
ReportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
- AddToMessageLog(FALSE, "Stopping service %s", _service_name);
+ AddToMessageLog(FALSE, "Stopped service %s", _service_name);
return 0;
}
@@ -785,6 +786,7 @@
switch (dwCtrlCode) {
case SERVICE_CONTROL_STOP:
+ case SERVICE_CONTROL_SHUTDOWN:
/* Call the stop handler that will actualy stop the service */
ServiceStop();
return;
@@ -889,7 +891,7 @@
goto cleanup;
}
}
- ReportServiceStatus(SERVICE_START_PENDING, NO_ERROR, 3000);
+ ReportServiceStatus(SERVICE_START_PENDING, NO_ERROR, 3);
if ((rc = ServiceStart()) == 0) {
AddToMessageLog(FALSE, "Service %s Main finished", _service_name);
}
Modified: trunk/utils/windows/native/service/jbosssvc/jboss.manifest
===================================================================
--- trunk/utils/windows/native/service/jbosssvc/jboss.manifest 2013-01-03 01:27:44 UTC
(rev 2979)
+++ trunk/utils/windows/native/service/jbosssvc/jboss.manifest 2013-01-04 10:25:51 UTC
(rev 2980)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
<!--
- Copyright(c) 2012 Red Hat Inc.,
+ Copyright(c) 2013 Red Hat Inc.,
and individual contributors as indicated by the @authors tag.
See the copyright.txt in the distribution for a
full listing of individual contributors.
Modified: trunk/utils/windows/native/service/jbosssvc/jboss.rc
===================================================================
--- trunk/utils/windows/native/service/jbosssvc/jboss.rc 2013-01-03 01:27:44 UTC (rev
2979)
+++ trunk/utils/windows/native/service/jbosssvc/jboss.rc 2013-01-04 10:25:51 UTC (rev
2980)
@@ -1,7 +1,7 @@
/*
* JBOSSSVC - JBoss Service helper
*
- * Copyright(c) 2012 Red Hat Middleware, LLC,
+ * Copyright(c) 2013 Red Hat Middleware, LLC,
* and individual contributors as indicated by the @authors tag.
* See the copyright.txt in the distribution for a
* full listing of individual contributors.
@@ -25,7 +25,7 @@
*/
#include <windows.h>
-#define STR_COPYRIGHT "Copyright � 2012 Red Hat Inc. " \
+#define STR_COPYRIGHT "Copyright � 2013 Red Hat Inc. " \
"or its licensors, as applicable."
#define STR_LICENSE "Distributable under LGPL license. " \