karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject svn commit: r1539271 - /karaf/trunk/main/src/main/java/org/apache/karaf/main/Stop.java
Date Wed, 06 Nov 2013 08:44:26 GMT
Author: jbonofre
Date: Wed Nov  6 08:44:25 2013
New Revision: 1539271

URL: http://svn.apache.org/r1539271
Log:
[KARAF-2547] Improve stop script with exit code and better messages

Modified:
    karaf/trunk/main/src/main/java/org/apache/karaf/main/Stop.java

Modified: karaf/trunk/main/src/main/java/org/apache/karaf/main/Stop.java
URL: http://svn.apache.org/viewvc/karaf/trunk/main/src/main/java/org/apache/karaf/main/Stop.java?rev=1539271&r1=1539270&r2=1539271&view=diff
==============================================================================
--- karaf/trunk/main/src/main/java/org/apache/karaf/main/Stop.java (original)
+++ karaf/trunk/main/src/main/java/org/apache/karaf/main/Stop.java Wed Nov  6 08:44:25 2013
@@ -23,6 +23,7 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.net.ConnectException;
 import java.net.Socket;
 
 /**
@@ -33,21 +34,40 @@ public class Stop {
     /**
      * Sends the shutdown command to the running karaf instance. Uses either a shut down
port configured in config.properties or
      * the port from the shutdown port file.
-     * 
+     *
      * @param args
      * @throws Exception
      */
     public static void main(String[] args) throws Exception {
         ConfigProperties config = new ConfigProperties();
         if (config.shutdownPort == 0 && config.portFile != null) {
-            config.shutdownPort = getPortFromShutdownPortFile(config.portFile);
+            try {
+                config.shutdownPort = getPortFromShutdownPortFile(config.portFile);
+            } catch (FileNotFoundException fnfe) {
+                System.err.println(config.portFile + " 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.exit(4);
+            }
         }
         if (config.shutdownPort > 0) {
-            Socket s = new Socket(config.shutdownHost, config.shutdownPort);
-            s.getOutputStream().write(config.shutdownCommand.getBytes());
-            s.close();
+            Socket s = null;
+            try {
+                s = new Socket(config.shutdownHost, config.shutdownPort);
+                s.getOutputStream().write(config.shutdownCommand.getBytes());
+                System.exit(0);
+            } 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