karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject svn commit: r1539328 - in /karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main: Status.java Stop.java
Date Wed, 06 Nov 2013 12:50:50 GMT
Author: jbonofre
Date: Wed Nov  6 12:50:49 2013
New Revision: 1539328

URL: http://svn.apache.org/r1539328
Log:
[KARAF-2547] Improve stop and status scripts with new exit codes

Modified:
    karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/Status.java
    karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/Stop.java

Modified: karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/Status.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/Status.java?rev=1539328&r1=1539327&r2=1539328&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/Status.java (original)
+++ karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/Status.java Wed Nov
 6 12:50:49 2013
@@ -18,13 +18,10 @@
  */
 package org.apache.karaf.main;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStreamReader;
+import java.io.*;
+import java.net.ConnectException;
 import java.net.Socket;
 import java.net.URL;
-import java.net.ConnectException;
 import java.util.Enumeration;
 import java.util.Properties;
 
@@ -62,10 +59,18 @@ public class Status {
         String portFile = props.getProperty(Main.KARAF_SHUTDOWN_PORT_FILE);
         String shutdown = props.getProperty(Main.KARAF_SHUTDOWN_COMMAND, Main.DEFAULT_SHUTDOWN_COMMAND);
         if (port == 0 && portFile != null) {
-            BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(portFile)));
-            String portStr = r.readLine();
-            port = Integer.parseInt(portStr);
-            r.close();
+            try {
+                BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(portFile)));
+                String portStr = r.readLine();
+                port = Integer.parseInt(portStr);
+                r.close();
+            } catch (FileNotFoundException fnfe) {
+                System.err.println(portFile + " shutdown port file doesn't exist. The container
is not running.");
+                System.exit(3);
+            } catch (IOException ioe) {
+                System.err.println("Can't read the " + portFile + " shutdown port file: "
+ ioe.getMessage());
+                System.exit(4);
+            }
         }
         if (port > 0) {
             Socket s = null;

Modified: karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/Stop.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/Stop.java?rev=1539328&r1=1539327&r2=1539328&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/Stop.java (original)
+++ karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/Stop.java Wed Nov
 6 12:50:49 2013
@@ -18,10 +18,8 @@
  */
 package org.apache.karaf.main;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStreamReader;
+import java.io.*;
+import java.net.ConnectException;
 import java.net.Socket;
 import java.net.URL;
 import java.util.Enumeration;
@@ -52,8 +50,7 @@ public class Stop {
         // Perform variable substitution for system properties.
         for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
             String name = (String) e.nextElement();
-            props.setProperty(name,
-                    Main.substVars(props.getProperty(name), name, null, props));
+            props.setProperty(name, Main.substVars(props.getProperty(name), name, null, props));
         }
 
         int port = Integer.parseInt(props.getProperty(Main.KARAF_SHUTDOWN_PORT, "0"));
@@ -61,17 +58,35 @@ public class Stop {
         String portFile = props.getProperty(Main.KARAF_SHUTDOWN_PORT_FILE);
         String shutdown = props.getProperty(Main.KARAF_SHUTDOWN_COMMAND, Main.DEFAULT_SHUTDOWN_COMMAND);
         if (port == 0 && portFile != null) {
-            BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(portFile)));
-            String portStr = r.readLine();
-            port = Integer.parseInt(portStr);
-            r.close();
+            try {
+                BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(portFile)));
+                String portStr = r.readLine();
+                port = Integer.parseInt(portStr);
+                r.close();
+            } catch (FileNotFoundException fnfe) {
+                System.err.println(portFile + " shutdown port file doesn't exist. The container
is not running.");
+                System.exit(3);
+            } catch (IOException ioe) {
+                System.err.println("Can't read the " + portFile + " shutdown port file: "
+ ioe.getMessage());
+                System.exit(4);
+            }
         }
         if (port > 0) {
-            Socket s = new Socket(host, port);
-            s.getOutputStream().write(shutdown.getBytes());
-            s.close();
+            Socket s = null;
+            try {
+                s = new Socket(host, port);
+                s.getOutputStream().write(shutdown.getBytes());
+            } catch (ConnectException connectException) {
+                System.err.println("Can't connect to the container. The container is not
running.");
+                System.exit(1);
+            } finally {
+                if (s != null) {
+                    s.close();
+                }
+            }
         } else {
             System.err.println("Unable to find port...");
+            System.exit(2);
         }
 
     }



Mime
View raw message