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 20:46:51 UTC
svn commit: r1536189 - in /karaf/branches/karaf-2.3.x:
assemblies/apache-karaf/src/main/distribution/unix-shell/bin/
assemblies/apache-karaf/src/main/distribution/windows-text/bin/
main/src/main/java/org/apache/karaf/main/
Author: jbonofre
Date: Sun Oct 27 19:46:50 2013
New Revision: 1536189
URL: http://svn.apache.org/r1536189
Log:
[KARAF-2138] Add status check option and script
Added:
karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/unix-shell/bin/status (with props)
karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/windows-text/bin/status.bat (with props)
karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/Status.java
Modified:
karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/unix-shell/bin/karaf
karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/windows-text/bin/karaf.bat
Modified: karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/unix-shell/bin/karaf
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/unix-shell/bin/karaf?rev=1536189&r1=1536188&r2=1536189&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/unix-shell/bin/karaf (original)
+++ karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/unix-shell/bin/karaf Sun Oct 27 19:46:50 2013
@@ -347,6 +347,10 @@ run() {
MAIN=org.apache.karaf.main.Stop
shift
;;
+ 'status')
+ MAIN=org.apache.karaf.main.Status
+ shift
+ ;;
'console')
shift
;;
Added: karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/unix-shell/bin/status
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/unix-shell/bin/status?rev=1536189&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/unix-shell/bin/status (added)
+++ karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/unix-shell/bin/status Sun Oct 27 19:46:50 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="status"
+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/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/unix-shell/bin/status
------------------------------------------------------------------------------
svn:executable = *
Modified: karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/windows-text/bin/karaf.bat
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/windows-text/bin/karaf.bat?rev=1536189&r1=1536188&r2=1536189&view=diff
==============================================================================
--- karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/windows-text/bin/karaf.bat (original)
+++ karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/windows-text/bin/karaf.bat Sun Oct 27 19:46:50 2013
@@ -269,6 +269,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
@@ -281,6 +282,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/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/windows-text/bin/status.bat
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/windows-text/bin/status.bat?rev=1536189&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/windows-text/bin/status.bat (added)
+++ karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/windows-text/bin/status.bat Sun Oct 27 19:46:50 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="status.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
Propchange: karaf/branches/karaf-2.3.x/assemblies/apache-karaf/src/main/distribution/windows-text/bin/status.bat
------------------------------------------------------------------------------
svn:executable = *
Added: 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=1536189&view=auto
==============================================================================
--- karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/Status.java (added)
+++ karaf/branches/karaf-2.3.x/main/src/main/java/org/apache/karaf/main/Status.java Sun Oct 27 19:46:50 2013
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+package org.apache.karaf.main;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.net.Socket;
+import java.net.URL;
+import java.net.ConnectException;
+import java.util.Enumeration;
+import java.util.Properties;
+
+/**
+ * Main class used to check the status of the root Karaf instance.
+ */
+public class Status {
+
+ public static void main(String[] args) throws Exception {
+ File karafHome = Utils.getKarafHome();
+ File karafBase = Utils.getKarafDirectory(Main.PROP_KARAF_BASE, Main.ENV_KARAF_BASE, karafHome, false, true);
+ File karafData = Utils.getKarafDirectory(Main.PROP_KARAF_DATA, Main.ENV_KARAF_DATA, new File(karafBase.getPath(), "data"), true, true);
+
+ System.setProperty(Main.PROP_KARAF_HOME, karafHome.getPath());
+ System.setProperty(Main.PROP_KARAF_BASE, karafBase.getPath());
+ System.setProperty(Main.PROP_KARAF_DATA, karafData.getPath());
+
+ // Load system properties.
+ Main.loadSystemProperties(karafBase);
+
+ File file = new File(new File(karafBase, "etc"), Main.CONFIG_PROPERTIES_FILE_NAME);
+ URL configPropURL = file.toURI().toURL();
+ Properties props = Main.loadPropertiesFile(configPropURL, false);
+ Main.copySystemProperties(props);
+
+ // 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));
+ }
+
+ int port = Integer.parseInt(props.getProperty(Main.KARAF_SHUTDOWN_PORT, "0"));
+ String host = props.getProperty(Main.KARAF_SHUTDOWN_HOST, "localhost");
+ 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();
+ }
+ if (port > 0) {
+ Socket s = null;
+ try {
+ s = new Socket(host, port);
+ if (s.isBound()) {
+ System.out.println("Running ...");
+ System.exit(0);
+ } else {
+ System.out.println("Not Running ...");
+ System.exit(1);
+ }
+ } catch (ConnectException connectionException) {
+ System.out.println("Not Running ...");
+ System.exit(1);
+ } finally {
+ if (s != null) {
+ s.close();
+ }
+ }
+ } else {
+ System.err.println("Unable to find port...");
+ }
+ }
+
+}