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 90D5110E3F for ; Wed, 6 Nov 2013 08:44:55 +0000 (UTC) Received: (qmail 79450 invoked by uid 500); 6 Nov 2013 08:44:55 -0000 Delivered-To: apmail-karaf-commits-archive@karaf.apache.org Received: (qmail 79386 invoked by uid 500); 6 Nov 2013 08:44:51 -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 79377 invoked by uid 99); 6 Nov 2013 08:44:49 -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 08:44:49 +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 08:44:47 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 3483B2388A3D; Wed, 6 Nov 2013 08:44:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1539271 - /karaf/trunk/main/src/main/java/org/apache/karaf/main/Stop.java Date: Wed, 06 Nov 2013 08:44:26 -0000 To: commits@karaf.apache.org From: jbonofre@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131106084426.3483B2388A3D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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); } }