You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2019/11/01 12:15:25 UTC

[karaf] branch karaf-4.2.x updated: [KARAF-6428] Consistency in bin/status to return running or not running only

This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch karaf-4.2.x
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/karaf-4.2.x by this push:
     new a7aa17e  [KARAF-6428] Consistency in bin/status to return running or not running only
a7aa17e is described below

commit a7aa17edb8b55369c4b579e74bc10d9ecb793b06
Author: Jean-Baptiste Onofré <jb...@apache.org>
AuthorDate: Fri Nov 1 07:38:23 2019 +0100

    [KARAF-6428] Consistency in bin/status to return running or not running only
    
    (cherry picked from commit 165b79174c96ff6f793741617494c8b80c759af2)
---
 main/src/main/java/org/apache/karaf/main/Status.java | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/main/src/main/java/org/apache/karaf/main/Status.java b/main/src/main/java/org/apache/karaf/main/Status.java
index 579a816..4d7a761 100644
--- a/main/src/main/java/org/apache/karaf/main/Status.java
+++ b/main/src/main/java/org/apache/karaf/main/Status.java
@@ -29,6 +29,9 @@ import java.net.Socket;
  */
 public class Status {
 
+    private final static String RUNNING = "Running ...";
+    private final static String NOT_RUNNING = "Not Running ...";
+
     /**
      * Checks if the shutdown port is bound. The shutdown port can be configured in config.properties
      * or in the shutdown port file.
@@ -42,10 +45,12 @@ public class Status {
             try {
                 config.shutdownPort = getPortFromShutdownPortFile(config.portFile);
             } catch (FileNotFoundException fnfe) {
-                System.err.println(config.portFile + " shutdown port file doesn't exist. The container is not running.");
+                System.out.println(NOT_RUNNING);
+                // cause with exit code 3: shutdown port file doesn't exist. The container is not running.
                 System.exit(3);
             } catch (IOException ioe) {
-                System.err.println("Can't read " + config.portFile + " port file: " + ioe.getMessage());
+                System.out.println(NOT_RUNNING);
+                // cause with exit code 4: can't read port file
                 System.exit(4);
             }
         }
@@ -54,14 +59,14 @@ public class Status {
             try {
                 s = new Socket(config.shutdownHost, config.shutdownPort);
                 if (s.isBound()) {
-                    System.out.println("Running ...");
+                    System.out.println(RUNNING);
                     System.exit(0);
                 } else {
-                    System.out.println("Not Running ...");
+                    System.out.println(NOT_RUNNING);
                     System.exit(1);
                 }
             } catch (ConnectException connectException) {
-                System.out.println("Not Running ...");
+                System.out.println(NOT_RUNNING);
                 System.exit(1);
             } finally {
                 if (s != null) {
@@ -73,10 +78,10 @@ public class Status {
             int pid = getPidFromPidFile(config.pidFile);
             org.apache.karaf.jpm.Process process = new ProcessBuilderFactoryImpl().newBuilder().attach(pid);
             if (process.isRunning()) {
-                System.out.println("Running ... (pid " + pid + ")");
+                System.out.println(RUNNING + " (pid " + pid + ")");
                 System.exit(0);
             } else {
-                System.out.println("Not Running ...");
+                System.out.println(NOT_RUNNING);
                 System.exit(1);
             }
         }