From 981fdba088b14f975555b9dceb92db614acf631c Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Fri, 25 Oct 2013 09:28:05 -0400
Subject: [PATCH 2/6] Fixed errors during Tomcat shutdown.
Previously the CMS.shutdown() was called multiple times during Tomcat
shutdown, one by CMSStarServlet.destroy() and the other by the shutdown
hook, causing some errors. The shutdown hook should only be used in a
standalone application, so it has been moved into CMS.main().
Bugzilla #1018628
---
base/common/src/com/netscape/certsrv/apps/CMS.java | 17 +++++++++++++++++
.../com/netscape/cms/servlet/base/CMSStartServlet.java | 3 +++
.../common/src/com/netscape/cmscore/apps/CMSEngine.java | 16 ----------------
3 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/base/common/src/com/netscape/certsrv/apps/CMS.java b/base/common/src/com/netscape/certsrv/apps/CMS.java
index 27cddad..fbcf65a 100644
--- a/base/common/src/com/netscape/certsrv/apps/CMS.java
+++ b/base/common/src/com/netscape/certsrv/apps/CMS.java
@@ -1661,5 +1661,22 @@ public final class CMS {
start(path);
} catch (EBaseException e) {
}
+
+ // Use shutdown hook in stand-alone application
+ // to catch SIGINT, SIGTERM, or SIGHUP.
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ public void run() {
+ /*LogDoc
+ *
+ * @phase watchdog check
+ */
+ CMS.getLogger().log(ILogger.EV_SYSTEM,
+ ILogger.S_OTHER,
+ ILogger.LL_INFO,
+ "CMSEngine: Received shutdown signal");
+
+ CMS.shutdown();
+ };
+ });
}
}
diff --git a/base/common/src/com/netscape/cms/servlet/base/CMSStartServlet.java b/base/common/src/com/netscape/cms/servlet/base/CMSStartServlet.java
index e00f2bd..34bbb2e 100644
--- a/base/common/src/com/netscape/cms/servlet/base/CMSStartServlet.java
+++ b/base/common/src/com/netscape/cms/servlet/base/CMSStartServlet.java
@@ -120,6 +120,9 @@ public class CMSStartServlet extends HttpServlet {
return "CMS startup servlet";
}
+ /**
+ * This method will be called when Tomcat is shutdown.
+ */
public void destroy() {
CMS.shutdown();
super.destroy();
diff --git a/base/common/src/com/netscape/cmscore/apps/CMSEngine.java b/base/common/src/com/netscape/cmscore/apps/CMSEngine.java
index 834918a..482b5ea 100644
--- a/base/common/src/com/netscape/cmscore/apps/CMSEngine.java
+++ b/base/common/src/com/netscape/cmscore/apps/CMSEngine.java
@@ -262,22 +262,6 @@ public class CMSEngine implements ICMSEngine {
* private constructor.
*/
public CMSEngine() {
-
- // Shutdown on SIGINT, SIGTERM, or SIGHUP.
- Runtime.getRuntime().addShutdownHook(new Thread() {
- public void run() {
- /*LogDoc
- *
- * @phase watchdog check
- */
- getLogger().log(ILogger.EV_SYSTEM,
- ILogger.S_OTHER,
- ILogger.LL_INFO,
- "OS: Received shutdown signal");
-
- shutdown();
- };
- });
}
/**
--
1.8.3.1