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 2013/10/27 11:55:19 UTC

svn commit: r1536090 - in /karaf/trunk: assemblies/features/framework/src/main/filtered-resources/resources/bin/ main/src/main/java/org/apache/karaf/main/

Author: jbonofre
Date: Sun Oct 27 10:55:19 2013
New Revision: 1536090

URL: http://svn.apache.org/r1536090
Log:
[KARAF-2138] Add status check option and script

Added:
    karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/status   (with props)
    karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/status.bat
    karaf/trunk/main/src/main/java/org/apache/karaf/main/Status.java
      - copied, changed from r1536019, karaf/trunk/main/src/main/java/org/apache/karaf/main/Stop.java
Modified:
    karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/karaf
    karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/karaf.bat
    karaf/trunk/main/src/main/java/org/apache/karaf/main/Stop.java

Modified: karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/karaf
URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/karaf?rev=1536090&r1=1536089&r2=1536090&view=diff
==============================================================================
--- karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/karaf (original)
+++ karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/karaf Sun Oct 27 10:55:19 2013
@@ -356,6 +356,10 @@ run() {
                 JAVA_OPTS="$JAVA_DEBUG_OPTS $JAVA_OPTS"
                 shift
                 ;;
+            'status')
+                MAIN=org.apache.karaf.main.Status
+                shift
+                ;;
             'stop')
                 MAIN=org.apache.karaf.main.Stop
                 shift

Modified: karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/karaf.bat
URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/karaf.bat?rev=1536090&r1=1536089&r2=1536090&view=diff
==============================================================================
--- karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/karaf.bat (original)
+++ karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/karaf.bat Sun Oct 27 10:55:19 2013
@@ -265,6 +265,7 @@ if "%KARAF_PROFILER%" == "" goto :RUN
 
 :RUN_LOOP
     if "%1" == "stop" goto :EXECUTE_STOP
+    if "%1" == "status" goto :EXECUTE_STATUS
     if "%1" == "console" goto :EXECUTE_CONSOLE
     if "%1" == "server" goto :EXECUTE_SERVER
     if "%1" == "client" goto :EXECUTE_CLIENT
@@ -277,6 +278,11 @@ if "%KARAF_PROFILER%" == "" goto :RUN
     shift
     goto :RUN_LOOP
 
+:EXECUTE_STATUS
+    SET MAIN=org.apache.karaf.main.Status
+    shift
+    goto :RUN_LOOP
+
 :EXECUTE_CONSOLE
     shift
     goto :RUN_LOOP

Added: karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/status
URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/status?rev=1536090&view=auto
==============================================================================
--- karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/status (added)
+++ karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/status Sun Oct 27 10:55:19 2013
@@ -0,0 +1,136 @@
+#!/bin/sh
+#
+#    Licensed to the Apache Software Foundation (ASF) under one or more
+#    contributor license agreements.  See the NOTICE file distributed with
+#    this work for additional information regarding copyright ownership.
+#    The ASF licenses this file to You under the Apache License, Version 2.0
+#    (the "License"); you may not use this file except in compliance with
+#    the License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#
+
+DIRNAME=`dirname $0`
+PROGNAME=`basename $0`
+
+#
+# Sourcing environment settings for karaf similar to tomcats setenv 
+#
+KARAF_SCRIPT="stop"
+export KARAF_SCRIPT
+if [ -f "$DIRNAME/setenv" ]; then
+  . "$DIRNAME/setenv"
+fi
+
+warn() {
+    echo "${PROGNAME}: $*"
+}
+
+die() {
+    warn "$*"
+    exit 1
+}
+
+detectOS() {
+    # OS specific support (must be 'true' or 'false').
+    cygwin=false;
+    darwin=false;
+    aix=false;
+    os400=false;
+    case "`uname`" in
+        CYGWIN*)
+            cygwin=true
+            ;;
+        Darwin*)
+            darwin=true
+            ;;
+        AIX*)
+            aix=true
+            ;;
+        OS400*)
+            os400=true
+            ;;
+    esac
+    # For AIX, set an environment variable
+    if $aix; then
+         export LDR_CNTRL=MAXDATA=0xB0000000@DSA
+         export IBM_JAVA_HEAPDUMP_TEXT=true
+         echo $LDR_CNTRL
+    fi
+}
+
+locateHome() {
+    if [ "x$KARAF_HOME" != "x" ]; then
+        warn "Ignoring predefined value for KARAF_HOME"
+    fi
+
+    # In POSIX shells, CDPATH may cause cd to write to stdout
+    (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+    KARAF_HOME=`cd $DIRNAME/..; pwd`
+    if [ ! -d "$KARAF_HOME" ]; then
+        die "KARAF_HOME is not valid: $KARAF_HOME"
+    fi
+}
+
+locateBase() {
+    if [ "x$KARAF_BASE" != "x" ]; then
+        if [ ! -d "$KARAF_BASE" ]; then
+            die "KARAF_BASE is not valid: $KARAF_BASE"
+        fi
+    else
+        KARAF_BASE=$KARAF_HOME
+    fi
+}
+
+locateData() {
+    if [ "x$KARAF_DATA" != "x" ]; then
+        if [ ! -d "$KARAF_DATA" ]; then
+            die "KARAF_DATA is not valid: $KARAF_DATA"
+        fi
+    else
+        KARAF_DATA=$KARAF_BASE/data
+    fi
+}
+
+init() {
+    # Determine if there is special OS handling we must perform
+    detectOS
+
+    # Locate the Karaf home directory
+    locateHome
+
+    # Locate the Karaf base directory
+    locateBase
+
+    # Locate the Karaf data directory
+    locateData
+}
+
+run() {
+    if $cygwin; then
+        KARAF_HOME=`cygpath --path --windows "$KARAF_HOME"`
+        KARAF_BASE=`cygpath --path --windows "$KARAF_BASE"`
+        KARAF_DATA=`cygpath --path --windows "$KARAF_DATA"`
+        CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+    fi
+    # Ensure the log directory exists -- we need to have a place to redirect stdout/stderr
+    if [ ! -d "$KARAF_DATA/log" ]; then
+        mkdir -p "$KARAF_DATA/log"
+    fi
+    exec "$KARAF_HOME"/bin/karaf status "$@"
+}
+
+main() {
+    init
+    run "$@"
+}
+
+main "$@"
+

Propchange: karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/status
------------------------------------------------------------------------------
    svn:executable = *

Added: karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/status.bat
URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/status.bat?rev=1536090&view=auto
==============================================================================
--- karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/status.bat (added)
+++ karaf/trunk/assemblies/features/framework/src/main/filtered-resources/resources/bin/status.bat Sun Oct 27 10:55:19 2013
@@ -0,0 +1,80 @@
+@echo off
+rem
+rem
+rem    Licensed to the Apache Software Foundation (ASF) under one or more
+rem    contributor license agreements.  See the NOTICE file distributed with
+rem    this work for additional information regarding copyright ownership.
+rem    The ASF licenses this file to You under the Apache License, Version 2.0
+rem    (the "License"); you may not use this file except in compliance with
+rem    the License.  You may obtain a copy of the License at
+rem
+rem       http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem    Unless required by applicable law or agreed to in writing, software
+rem    distributed under the License is distributed on an "AS IS" BASIS,
+rem    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem    See the License for the specific language governing permissions and
+rem    limitations under the License.
+rem
+
+if not "%ECHO%" == "" echo %ECHO%
+
+setlocal
+set DIRNAME=%~dp0%
+set PROGNAME=%~nx0%
+set ARGS=%*
+
+rem Sourcing environment settings for karaf similar to tomcats setenv
+SET KARAF_SCRIPT="stop.bat"
+if exist "%DIRNAME%setenv.bat" (
+  call "%DIRNAME%setenv.bat"
+)
+
+rem Check console window title. Set to Karaf by default
+if not "%KARAF_TITLE%" == "" (
+    title %KARAF_TITLE%
+) else (
+    title Karaf
+)
+
+goto BEGIN
+
+:warn
+    echo %PROGNAME%: %*
+goto :EOF
+
+:BEGIN
+
+rem # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+if not "%KARAF_HOME%" == "" (
+    call :warn Ignoring predefined value for KARAF_HOME
+)
+set KARAF_HOME=%DIRNAME%..
+if not exist "%KARAF_HOME%" (
+    call :warn KARAF_HOME is not valid: "%KARAF_HOME%"
+    goto END
+)
+
+if not "%KARAF_BASE%" == "" (
+    if not exist "%KARAF_BASE%" (
+       call :warn KARAF_BASE is not valid: "%KARAF_BASE%"
+       goto END
+    )
+)
+if "%KARAF_BASE%" == "" (
+  set "KARAF_BASE=%KARAF_HOME%"
+)
+
+:EXECUTE
+    "%KARAF_HOME%\bin\karaf.bat" status
+
+rem # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+
+:END
+
+endlocal
+
+if not "%PAUSE%" == "" pause
+
+:END_NO_PAUSE

Copied: karaf/trunk/main/src/main/java/org/apache/karaf/main/Status.java (from r1536019, 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/Status.java?p2=karaf/trunk/main/src/main/java/org/apache/karaf/main/Status.java&p1=karaf/trunk/main/src/main/java/org/apache/karaf/main/Stop.java&r1=1536019&r2=1536090&rev=1536090&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/Status.java Sun Oct 27 10:55:19 2013
@@ -18,22 +18,19 @@
  */
 package org.apache.karaf.main;
 
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStreamReader;
+import java.io.*;
+import java.net.ConnectException;
 import java.net.Socket;
 
 /**
- * Main class used to stop the root Karaf instance
+ * Main class used to check the status of the root Karaf instance.
  */
-public class Stop {
+public class Status {
 
     /**
-     * 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.
-     * 
+     * Checks if the shutdown port is bound. The shutdown port can be configured in config.properties
+     * or in the shutdown port file.
+     *
      * @param args
      * @throws Exception
      */
@@ -43,13 +40,28 @@ public class Stop {
             config.shutdownPort = getPortFromShutdownPortFile(config.portFile);
         }
         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);
+                if (s.isBound()) {
+                    System.out.println("Running ...");
+                    System.exit(0);
+                } else {
+                    System.out.println("Not Running ...");
+                    System.exit(1);
+                }
+            } catch (ConnectException connectException) {
+                System.out.println("Not Running ...");
+                System.exit(1);
+            } finally {
+                if (s != null) {
+                    s.close();
+                }
+            }
         } else {
             System.err.println("Unable to find port...");
+            System.exit(2);
         }
-
     }
 
     private static int getPortFromShutdownPortFile(String portFile) throws FileNotFoundException, IOException {
@@ -60,4 +72,5 @@ public class Stop {
         r.close();
         return port;
     }
+
 }

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=1536090&r1=1536089&r2=1536090&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 Sun Oct 27 10:55:19 2013
@@ -60,4 +60,5 @@ public class Stop {
         r.close();
         return port;
     }
+
 }