Author: mladen.turk(a)jboss.com
Date: 2012-12-18 01:17:26 -0500 (Tue, 18 Dec 2012)
New Revision: 2974
Added:
trunk/utils/windows/native/service/jbosssvc/jboss.manifest
Modified:
trunk/utils/windows/native/service/jbosssvc/jboss.c
trunk/utils/windows/native/service/jbosssvc/jboss.rc
Log:
Fix shutdown timeout logic
Modified: trunk/utils/windows/native/service/jbosssvc/jboss.c
===================================================================
--- trunk/utils/windows/native/service/jbosssvc/jboss.c 2012-10-15 15:23:34 UTC (rev
2973)
+++ trunk/utils/windows/native/service/jbosssvc/jboss.c 2012-12-18 06:17:26 UTC (rev
2974)
@@ -1,7 +1,7 @@
/*
* JBOSSSVC - JBoss Service helper
*
- * Copyright(c) 2007 Red Hat Middleware, LLC,
+ * Copyright(c) 2012 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.
@@ -96,6 +96,7 @@
static LPCSTR REG_SERVFILE = "ServiceFile";
static LPCSTR REG_LOGFILE = "LogFile";
static LPCSTR REG_WPATH = "WorkingPath";
+static LPCSTR REG_SHTMO = "ShutdownTimeout";
/* Main servic table entry
@@ -115,9 +116,10 @@
static char _service_image[MAX_PATH + 1];
static char _service_bat[MAX_PATH + 1];
static char _cmd_exe[MAX_PATH + 1];
-static BOOL _service_log = FALSE;
-static BOOL _verbose_log = TRUE;
+static DWORD _service_log = 1;
+static DWORD _verbose_log = 0;
static DWORD _service_auto = SERVICE_AUTO_START;
+static DWORD _service_shtm = 20;
enum _service_mode_e {
mode_none,
@@ -155,46 +157,6 @@
return rv;
}
-static DWORD WaitToKillServiceTimeout()
-{
- static DWORD dwTimeout = 0;
-
- if (dwTimeout) {
- return dwTimeout;
- }
- else {
- DWORD err;
- HKEY hKey;
- CHAR wsBuf[MAX_PATH];
- DWORD dwLen, dwType = REG_SZ;
-
- dwTimeout = 20000;
- if ((err = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
- "SYSTEM\\CurrentControlSet\\Control",
- 0,
- KEY_READ,
- &hKey)) != ERROR_SUCCESS) {
- return dwTimeout;
- }
-
- dwLen = sizeof(wsBuf);
- err = RegQueryValueExA(hKey,
- "WaitToKillServiceTimeout",
- NULL,
- &dwType,
- (LPBYTE)wsBuf,
- &dwLen);
- RegCloseKey(hKey);
- if (err == ERROR_SUCCESS) {
- dwTimeout = (DWORD)atoi(wsBuf);
- if (!dwTimeout)
- dwTimeout = 20000;
- }
-
- return dwTimeout;
- }
-}
-
/* To share the semaphores with other processes, we need a NULL ACL
* Code from MS KB Q106387
*/
@@ -324,6 +286,7 @@
fprintf(stderr, " -d Service display name\n");
fprintf(stderr, " -c Service description\n");
fprintf(stderr, " -w Service working path\n");
+ fprintf(stderr, " -z Service shutdown time in seconds (min. 10)\n");
fprintf(stderr, " -l Turn info logging On\n");
fprintf(stderr, " -s Sleep 1 second and exit\n");
fprintf(stderr, " -m Start service manually\n");
@@ -543,8 +506,14 @@
rc = RegQueryValueEx(hKey, REG_LOGFILE, NULL, &dwType,
(LPBYTE)&_service_log, &dwSize);
if (rc != ERROR_SUCCESS || dwType != REG_DWORD) {
- _service_log = FALSE;
+ _service_log = 0;
}
+ dwSize = sizeof(DWORD);
+ rc = RegQueryValueEx(hKey, REG_SHTMO, NULL, &dwType,
+ (LPBYTE)&_service_shtm, &dwSize);
+ if (rc != ERROR_SUCCESS || dwType != REG_DWORD) {
+ _service_shtm = 20;
+ }
dwSize = MAX_PATH + 1;
rc = RegQueryValueEx(hKey, REG_WPATH, NULL, &dwType,
(LPBYTE)_working_path, &dwSize);
@@ -706,7 +675,7 @@
return bResult;
}
-static BOOL TerminateProcessGroup(HANDLE hProcess, DWORD dwProcessId, UINT retCode)
+static BOOL TerminateProcessGroup(DWORD dwProcessId, UINT retCode)
{
HANDLE hProcessSnap;
PROCESSENTRY32 pe32;
@@ -735,48 +704,41 @@
CloseHandle(hProcessSnap);
Sleep(500);
- return TerminateProcess(hProcess, retCode);
+ if (_service_run_hproc != NULL) {
+ if (WaitForSingleObject(_service_run_hproc, 500) == WAIT_TIMEOUT)
+ return TerminateProcess(_service_run_hproc, retCode);
+ }
+ return TRUE;
}
/* Executed when the service receives stop event */
static DWORD ServiceStop()
{
- int step = 14000;
PROCESS_INFORMATION prInfo;
char cmd[MAX_CMDLINE + 1];
- time_t s;
- double t;
if (!IsServiceRunning(_service_name)) {
AddToMessageLog(FALSE, "Service %s is already stopped",
_service_name);
return 0;
}
- t = WaitToKillServiceTimeout() / 1000 - 2;
- time(&s);
BuildCommandLine(cmd, "stop");
AddToMessageLog(FALSE, "Stopping service %s", _service_name);
- ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR,
- WaitToKillServiceTimeout());
+ ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, _service_shtm);
- while (RunChildProcess(_cmd_exe, cmd, &prInfo)) {
+ if (RunChildProcess(_cmd_exe, cmd, &prInfo)) {
WaitForSingleObject(prInfo.hProcess, INFINITE);
AddToMessageLog(FALSE, "Stopped service %s", _service_name);
CloseHandle(prInfo.hProcess);
CloseHandle(prInfo.hThread);
ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
- if (WaitForSingleObject(_service_run_event, step) == WAIT_OBJECT_0)
- break;
-
- if (step > 2000)
- step = 2000;
- if (difftime(time(NULL), s) > t) {
+ if (WaitForSingleObject(_service_run_event, _service_shtm * 1000) ==
WAIT_TIMEOUT) {
ReportServiceStatus(SERVICE_STOP_PENDING, NO_ERROR, 0);
- TerminateProcessGroup(_service_run_hproc, _service_run_pid, 1);
- AddToMessageLog(FALSE, "Service terminated %s", _service_name);
+ TerminateProcessGroup(_service_run_pid, 1);
+ AddToMessageLog(FALSE, "Service forcibly terminated %s",
_service_name);
}
}
ReportServiceStatus(SERVICE_STOPPED, NO_ERROR, 0);
@@ -973,6 +935,7 @@
int need_desc = 0;
int need_disp = 0;
int need_path = 0;
+ int need_shtm = 0;
int kill_code = 0;
if (argc < 3) {
@@ -1036,15 +999,22 @@
need_path = 1;
args_left++;
break;
+ case 'z':
+ need_shtm = 1;
+ args_left++;
+ break;
case 'l':
- _service_log = TRUE;
+ _service_log = 1;
break;
case 'm':
_service_auto = SERVICE_DEMAND_START;
break;
case 'q':
- _verbose_log = FALSE;
+ _verbose_log = 0;
break;
+ case 'v':
+ _verbose_log = 1;
+ break;
default:
ErrorUsage();
break;
@@ -1069,6 +1039,11 @@
lstrcpy(_service_disp, argv[i++]);
if (need_desc)
lstrcpy(_service_desc, argv[i++]);
+ if (need_shtm) {
+ _service_shtm = atoi(argv[i++]);
+ if (_service_shtm < 10)
+ ErrorUsage();
+ }
if (_service_mode != mode_signal) {
_service_run_event = CreateEvent(NULL, TRUE, FALSE, NULL);
Added: trunk/utils/windows/native/service/jbosssvc/jboss.manifest
===================================================================
--- trunk/utils/windows/native/service/jbosssvc/jboss.manifest
(rev 0)
+++ trunk/utils/windows/native/service/jbosssvc/jboss.manifest 2012-12-18 06:17:26 UTC
(rev 2974)
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
+<!--
+
+ Copyright(c) 2012 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.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library in the file COPYING.LIB;
+ if not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+
+-->
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
+<assemblyIdentity version="3.1.0.0" processorArchitecture="*"
name="JBoss.AS.JBosssvc" type="win32" />
+<description>JBoss Service helper</description>
+<dependency>
+<dependentAssembly>
+<assemblyIdentity type="win32"
name="Microsoft.Windows.Common-Controls" version="6.0.0.0"
processorArchitecture="*" publicKeyToken="6595b64144ccf1df"
language="*" />
+</dependentAssembly>
+</dependency>
+<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+<security>
+<!-- Windows UAC support -->
+<requestedPrivileges>
+<requestedExecutionLevel level="requireAdministrator"
uiAccess="false"></requestedExecutionLevel>
+</requestedPrivileges>
+</security>
+</trustInfo>
+</assembly>
Property changes on: trunk/utils/windows/native/service/jbosssvc/jboss.manifest
___________________________________________________________________
Added: svn:mime-type
+ text/xml
Added: svn:eol-style
+ native
Modified: trunk/utils/windows/native/service/jbosssvc/jboss.rc
===================================================================
--- trunk/utils/windows/native/service/jbosssvc/jboss.rc 2012-10-15 15:23:34 UTC (rev
2973)
+++ trunk/utils/windows/native/service/jbosssvc/jboss.rc 2012-12-18 06:17:26 UTC (rev
2974)
@@ -1,7 +1,7 @@
/*
* JBOSSSVC - JBoss Service helper
*
- * Copyright(c) 2007 Red Hat Middleware, LLC,
+ * Copyright(c) 2012 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 � 2009 Red Hat Middleware, LLC. " \
+#define STR_COPYRIGHT "Copyright � 2012 Red Hat Inc. " \
"or its licensors, as applicable."
#define STR_LICENSE "Distributable under LGPL license. " \
@@ -34,8 +34,8 @@
#define STR_COMPANY "Red Hat�, Inc."
#define STR_TRADEMARK "� Red Hat Inc."
#define STR_PRODUCT "JBoss Service wrapper"
-#define STR_VERISON "1.2.4.0"
-#define CSV_VERISON 1,2,4,0
+#define STR_VERISON "1.2.5.0"
+#define CSV_VERISON 1,2,5,0
#define PRIVATE_BUILD 0
#define PRERELEASE_BUILD 0
@@ -61,7 +61,8 @@
#endif
-IDI_MAINICON ICON "jboss.ico"
+IDI_MAINICON ICON "jboss.ico"
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "jboss.manifest"
LANGUAGE 0x9,0x1
1 11 MSG00001.bin