Return-Path: X-Original-To: apmail-karaf-commits-archive@minotaur.apache.org Delivered-To: apmail-karaf-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 81D1110467 for ; Wed, 6 Nov 2013 12:40:41 +0000 (UTC) Received: (qmail 70768 invoked by uid 500); 6 Nov 2013 12:40:39 -0000 Delivered-To: apmail-karaf-commits-archive@karaf.apache.org Received: (qmail 69759 invoked by uid 500); 6 Nov 2013 12:40:34 -0000 Mailing-List: contact commits-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list commits@karaf.apache.org Received: (qmail 69696 invoked by uid 99); 6 Nov 2013 12:40:32 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Nov 2013 12:40:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Nov 2013 12:40:29 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 25A9423889BB; Wed, 6 Nov 2013 12:40:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1539325 - in /karaf/branches/karaf-2.x/main/src/main/java/org/apache/karaf/main: Status.java Stop.java Date: Wed, 06 Nov 2013 12:40:08 -0000 To: commits@karaf.apache.org From: jbonofre@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131106124008.25A9423889BB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jbonofre Date: Wed Nov 6 12:40:07 2013 New Revision: 1539325 URL: http://svn.apache.org/r1539325 Log: [KARAF-2547] Improve stop and status scripts with new exit codes Modified: karaf/branches/karaf-2.x/main/src/main/java/org/apache/karaf/main/Status.java karaf/branches/karaf-2.x/main/src/main/java/org/apache/karaf/main/Stop.java Modified: karaf/branches/karaf-2.x/main/src/main/java/org/apache/karaf/main/Status.java URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/main/src/main/java/org/apache/karaf/main/Status.java?rev=1539325&r1=1539324&r2=1539325&view=diff ============================================================================== --- karaf/branches/karaf-2.x/main/src/main/java/org/apache/karaf/main/Status.java (original) +++ karaf/branches/karaf-2.x/main/src/main/java/org/apache/karaf/main/Status.java Wed Nov 6 12:40:07 2013 @@ -18,10 +18,7 @@ */ 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; @@ -69,10 +66,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.x/main/src/main/java/org/apache/karaf/main/Stop.java URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.x/main/src/main/java/org/apache/karaf/main/Stop.java?rev=1539325&r1=1539324&r2=1539325&view=diff ============================================================================== --- karaf/branches/karaf-2.x/main/src/main/java/org/apache/karaf/main/Stop.java (original) +++ karaf/branches/karaf-2.x/main/src/main/java/org/apache/karaf/main/Stop.java Wed Nov 6 12:40:07 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); } }