[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Pki-devel] [PATCH] 610 Startup log message improvementes.



The PKIListener has been modified to verify that all subsystems
are running and to show the command to enable the subsystem if it
was disabled due to errors.

https://fedorahosted.org/pki/ticket/1406

--
Endi S. Dewata
From 5b2d10054acb81ec55cc12b523c9e6b20801cc63 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata redhat com>
Date: Mon, 15 Jun 2015 00:04:10 -0400
Subject: [PATCH] Startup log message improvementes.

The PKIListener has been modified to verify that all subsystems
are running and to show the command to enable the subsystem if it
was disabled due to errors.

https://fedorahosted.org/pki/ticket/1406
---
 .classpath                                         |   1 +
 .../src/com/netscape/certsrv/common/Constants.java |   1 -
 .../src/com/netscape/cmscore/apps/CMSEngine.java   |   4 +-
 base/server/share/conf/log4j.properties            |   1 +
 base/server/tomcat/src/CMakeLists.txt              |  11 ++-
 .../src/com/netscape/cms/tomcat/PKIListener.java   | 103 +++++++++++++++++++--
 specs/pki-core.spec                                |   5 +
 7 files changed, 116 insertions(+), 10 deletions(-)

diff --git a/.classpath b/.classpath
index 9fd5144bf32f3a4af6b6992f7b5027ef55d9f2df..c8f17a12c741c0073438511a298ba3b048d9634d 100644
--- a/.classpath
+++ b/.classpath
@@ -59,5 +59,6 @@
 	<classpathentry kind="lib" path="/usr/lib/java/nuxwdog.jar"/>
 	<classpathentry kind="lib" path="/usr/lib/java/jss4.jar"/>
 	<classpathentry kind="lib" path="/usr/share/java/tomcatjss.jar"/>
+	<classpathentry kind="lib" path="/usr/share/java/log4j.jar"/>
 	<classpathentry kind="output" path="build/classes"/>
 </classpath>
diff --git a/base/common/src/com/netscape/certsrv/common/Constants.java b/base/common/src/com/netscape/certsrv/common/Constants.java
index 100b91110cc3d1f77da3cb1d5c8a19b7057f232b..e37d807346ca8efe1c44199a12c142bfa0b7fda0 100644
--- a/base/common/src/com/netscape/certsrv/common/Constants.java
+++ b/base/common/src/com/netscape/certsrv/common/Constants.java
@@ -553,7 +553,6 @@ public interface Constants {
      *========================================================*/
 
     public final static String SERVER_STARTUP_WARNING_MESSAGE = "CMS Warning: ";
-    public final static String SERVER_STARTUP_MESSAGE = "Server is started.";
     public final static String SERVER_SHUTDOWN_MESSAGE = "Shutting down.";
     public final static String SERVER_SHUTDOWN_ERROR_MESSAGE = "Error Starting CMS: ";
     public final static String SERVER_SHUTDOWN_EXTENDED_ERROR_MESSAGE = "Extended error information: ";
diff --git a/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java b/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java
index 729fb4a80c8a560b7adc4b63c738678fe273af0b..02c8ab41db38b781e8a1db05c7c26c8a98f2b9ac 100644
--- a/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java
+++ b/base/server/cmscore/src/com/netscape/cmscore/apps/CMSEngine.java
@@ -1183,7 +1183,9 @@ public class CMSEngine implements ICMSEngine {
          */
         Logger.getLogger().log(ILogger.EV_SYSTEM, ILogger.S_ADMIN,
                 ILogger.LL_INFO, CMS.getLogMessage("SERVER_STARTUP"));
-        System.out.println(Constants.SERVER_STARTUP_MESSAGE);
+
+        String type = mConfig.get("cs.type");
+        System.out.println(type + " is started.");
         isStarted = true;
 
     }
diff --git a/base/server/share/conf/log4j.properties b/base/server/share/conf/log4j.properties
index dd4bd9318b4bd4f416e05a4d830d992a7a86f4b6..f0a33b067011cf0faf5487c8e7c704c6cd313916 100644
--- a/base/server/share/conf/log4j.properties
+++ b/base/server/share/conf/log4j.properties
@@ -28,3 +28,4 @@ log4j.category.org.jboss.resteasy.plugins.providers=debug
 log4j.category.org.jboss.resteasy.specimpl=debug
 log4j.category.org.jboss.resteasy.plugins.server=debug
 log4j.logger.org.jboss.resteasy.mock=debug
+log4j.logger.com.netscape.cms.tomcat=INFO
diff --git a/base/server/tomcat/src/CMakeLists.txt b/base/server/tomcat/src/CMakeLists.txt
index 669cc8883043062119afdb5b55db28828d09e92f..149d4927d76656312b1fe2b000179b60ac95364b 100644
--- a/base/server/tomcat/src/CMakeLists.txt
+++ b/base/server/tomcat/src/CMakeLists.txt
@@ -37,6 +37,14 @@ find_file(APACHE_COMMONS_LANG_JAR
         /usr/share/java
 )
 
+find_file(LOG4J_JAR
+    NAMES
+        log4j-1.2.17.jar
+        log4j.jar
+    PATHS
+        /usr/share/java
+)
+
 find_file(TOMCAT_CATALINA_JAR
     NAMES
         catalina.jar
@@ -139,7 +147,8 @@ javac(pki-tomcat-classes
         com/netscape/cms/tomcat/*.java
     CLASSPATH
         ${SERVLET_JAR} ${TOMCAT_CATALINA_JAR} ${TOMCAT_UTIL_SCAN_JAR}
-		${NUXWDOG_JAR} ${APACHE_COMMONS_LANG_JAR} ${TOMCATJSS_JAR}
+		${APACHE_COMMONS_LANG_JAR} ${LOG4J_JAR}
+		${NUXWDOG_JAR} ${TOMCATJSS_JAR}
     OUTPUT_DIR
         ${CMAKE_BINARY_DIR}/../../tomcat
 )
diff --git a/base/server/tomcat/src/com/netscape/cms/tomcat/PKIListener.java b/base/server/tomcat/src/com/netscape/cms/tomcat/PKIListener.java
index abd88c1a61ecb3a6ffb8cc4e2ce6aad96eee1d12..1a0a69927150f772334dbd613967d45febeac2f4 100644
--- a/base/server/tomcat/src/com/netscape/cms/tomcat/PKIListener.java
+++ b/base/server/tomcat/src/com/netscape/cms/tomcat/PKIListener.java
@@ -1,33 +1,122 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program 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 General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2015 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
 package com.netscape.cms.tomcat;
+
+import java.io.File;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleEvent;
 import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Server;
+import org.apache.catalina.Service;
 import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
 
 import com.redhat.nuxwdog.WatchdogClient;
 
 public class PKIListener implements LifecycleListener {
 
+    private Logger log = Logger.getLogger(PKIListener.class);
+
     private boolean startedByWD = false;
 
     @Override
     public void lifecycleEvent(LifecycleEvent event) {
-        String method = "NuxwdogReader:lifecycleEvent";
-        if (event.getType().equals(Lifecycle.BEFORE_INIT_EVENT)) {
-            System.out.println(method + ": before init event");
+
+        String type = event.getType();
+        log.debug(event.getLifecycle().getClass().getName() + "[" + type + "]");
+
+        if (type.equals(Lifecycle.BEFORE_INIT_EVENT)) {
+
             String wdPipeName = System.getenv("WD_PIPE_NAME");
             if (StringUtils.isNotEmpty(wdPipeName)) {
                 startedByWD = true;
-                System.out.println(method + ": Initializing the watchdog");
+                log.info("Initializing the watchdog");
                 WatchdogClient.init();
             }
-        } else if (event.getType().equals(Lifecycle.AFTER_START_EVENT)) {
-            System.out.println(method + "After start event");
+
+        } else if (type.equals(Lifecycle.AFTER_START_EVENT)) {
+
             if (startedByWD) {
-                System.out.println(method + ": Sending endInit to the Watchdog");
+                log.info("Sending endInit to the Watchdog");
                 WatchdogClient.sendEndInit(0);
             }
+
+            verifySubsystems((Server)event.getLifecycle());
         }
     }
 
+    public void verifySubsystems(Server server) {
+
+        Service service = server.findService("Catalina");
+        Engine engine = (Engine)service.getContainer();
+        String defaultHost = engine.getDefaultHost();
+        Host host = (Host)engine.findChild(defaultHost);
+
+        File instanceDir = new File(System.getProperty("catalina.base"));
+        String instanceName = instanceDir.getName();
+
+        for (File file : instanceDir.listFiles()) {
+
+            if (!file.isDirectory()) continue;
+
+            File csCfg = new File(file, "conf" + File.separator + "CS.cfg");
+            if (!csCfg.exists()) continue;
+
+            String subsystemName = file.getName();
+
+            File contextXml = new File(
+                    instanceDir,
+                    "conf" + File.separator + "Catalina" + File.separator +
+                    defaultHost + File.separator + subsystemName + ".xml");
+
+            if (!contextXml.exists()) {
+
+                log.error("Subsystem " + subsystemName.toUpperCase() + " is disabled.");
+
+                String selftestsLog = "/var/log/pki/" + instanceName + "/" + subsystemName + "/selftests.log";
+                log.error("Check " + selftestsLog + " for possible errors.");
+
+                log.error("To enable the subsystem:");
+                log.error("  pki-server subsystem-enable -i " + instanceName + " " + subsystemName);
+
+                continue;
+            }
+
+            Context context = (Context)host.findChild("/" + subsystemName);
+
+            if (context == null) {
+
+                log.error("Subsystem " + subsystemName.toUpperCase() + " is not deployed.");
+
+                String catalinaLog = "/var/log/pki/" + instanceName + "/catalina.*.log";
+                log.error("Check " + catalinaLog);
+                log.error("and Tomcat's standard output and error for possible errors:");
+                log.error("  journalctl -u pki-tomcatd@" + instanceName + ".service");
+
+                continue;
+            }
+
+            log.info("Subsystem " + subsystemName.toUpperCase() + " is running.");
+        }
+    }
 }
diff --git a/specs/pki-core.spec b/specs/pki-core.spec
index 3c5589a342c8132e33985fd9d4c592298111f691..4d55e2365e73ae2925a92c9bd61ad098538ab8ed 100644
--- a/specs/pki-core.spec
+++ b/specs/pki-core.spec
@@ -273,6 +273,11 @@ Requires:         javassist
 Requires:         jpackage-utils >= 0:1.7.5-10
 Requires:         jss >= 4.2.6-35
 Requires:         ldapjdk
+%if 0%{?fedora} >= 22
+Requires:         log4j12
+%else
+Requires:         log4j
+%endif
 Requires:         python-ldap
 Requires:         python-lxml
 Requires:         python-requests >= 1.1.0-3
-- 
1.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]