You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by sp...@apache.org on 2005/11/08 14:47:33 UTC

svn commit: r331820 - in /geronimo/trunk/modules: assembly/ assembly/src/scripts/ deploy-tool/src/java/org/apache/geronimo/deployment/ deploy-tool/src/java/org/apache/geronimo/deployment/cli/

Author: sppatel
Date: Tue Nov  8 05:47:28 2005
New Revision: 331820

URL: http://svn.apache.org/viewcvs?rev=331820&view=rev
Log:
shutdown script support

Added:
    geronimo/trunk/modules/assembly/src/scripts/shutdown.bat
    geronimo/trunk/modules/assembly/src/scripts/shutdown.sh
    geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/ShutdownBootstrap.java
    geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/StopServer.java
Modified:
    geronimo/trunk/modules/assembly/maven.xml

Modified: geronimo/trunk/modules/assembly/maven.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/maven.xml?rev=331820&r1=331819&r2=331820&view=diff
==============================================================================
--- geronimo/trunk/modules/assembly/maven.xml (original)
+++ geronimo/trunk/modules/assembly/maven.xml Tue Nov  8 05:47:28 2005
@@ -344,6 +344,10 @@
                 name="bootstrap"
                 className="org.apache.geronimo.deployment.Bootstrap"
                 method="bootstrap"/>
+        	    <define:jellybean
+        	    	   name="shutdown"
+        	    	   className="org.apache.geronimo.deployment.ShutdownBootstrap"
+        	    	   method="bootstrap"/>
         </define:taglib>
 
         <bootstrap:bootstrap
@@ -356,7 +360,12 @@
             deployerGBean="geronimo.deployer:name=Deployer,J2EEApplication=null,J2EEModule=org/apache/geronimo/OfflineDeployer,j2eeType=Deployer,J2EEServer=deployer"
             deploymentFactory="org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryImpl"
             />
-
+    	
+    	    <bootstrap:shutdown
+    	            shutdownJar="${geronimo.assembly.dir}/bin/shutdown.jar"
+    	            shutdownClassPath="${deploy.classpath}"
+    	            />
+    	
         <!-- build the system configuration and server.jar -->
         <ant:echo file="${basedir}/target/deploy-commands">package --classPath "${server.classpath}" --mainClass org.apache.geronimo.system.main.Daemon --endorsedDirs lib/endorsed --extensionDirs lib/ext --install target/plan/system-plan.xml ${geronimo.assembly.dir}/bin/server.jar${line.separator}</ant:echo>
         

Added: geronimo/trunk/modules/assembly/src/scripts/shutdown.bat
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/src/scripts/shutdown.bat?rev=331820&view=auto
==============================================================================
--- geronimo/trunk/modules/assembly/src/scripts/shutdown.bat (added)
+++ geronimo/trunk/modules/assembly/src/scripts/shutdown.bat Tue Nov  8 05:47:28 2005
@@ -0,0 +1,78 @@
+@rem
+@rem  Copyright 2005 The Apache Software Foundation
+@rem
+@rem   Licensed under the Apache License, Version 2.0 (the "License");
+@rem   you may not use this file except in compliance with the License.
+@rem   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
+@rem --------------------------------------------------------------------
+@rem $Rev$ $Date$
+@rem --------------------------------------------------------------------
+@echo off
+
+@rem Verify we are running on Windows XP or Server
+if not "%OS%"=="Windows_NT" goto FailOS
+setlocal
+goto Init
+
+:FailOS
+echo Error - Unrecognized OS type.
+echo.
+set ERRORLEVEL=1
+goto End
+
+:Init
+@rem Capture any passed in arguments
+set ARGS=%*
+@rem Capture the current dir the script was started in
+set CUR_DIR="%cd%"
+for %%z in (%CUR_DIR%) do set CUR_DIR=%%~sz
+
+@rem Set the path to the shutdown.jar
+set SHUTDOWN_JAR="%~dp0shutdown.jar"
+for %%z in (%SHUTDOWN_JAR%) do set SHUTDOWN_JAR=%%~sz
+
+:CheckDeployerJar
+@rem Verify the shutdown.jar exists:
+if exist "%SHUTDOWN_JAR%" goto CheckJavaHome
+echo Error - Unable to locate the deployer jar file.
+echo.
+set ERRORLEVEL=1
+goto End
+
+:CheckJavaHome
+for %%z in ("%JAVA_HOME%") do set JAVA_HOME=%%~sz
+if not "%JAVA_HOME%"=="" goto CheckJavaExe
+echo Error - The JAVA_HOME env variable MUST be set.
+echo.
+set ERRORLEVEL=1
+goto End
+
+:CheckJavaExe
+if not exist "%JAVA_HOME%\bin" goto FailJavaHome
+if not exist "%JAVA_HOME%\bin\java.exe" goto FailJavaHome
+set JAVA="%JAVA_HOME%\bin\java.exe"
+goto StartDeployer
+
+:FailJavaHome
+echo Error - Unable to locate Java binary under the JAVA_HOME:
+echo   JAVA_HOME: [ %JAVA_HOME%\bin\java.exe ]
+echo.
+set ERRORLEVEL=1
+goto End
+
+:StartDeployer
+%JAVA% -jar %SHUTDOWN_JAR% %ARGS%
+
+:End
+echo.
+@endlocal
+

Added: geronimo/trunk/modules/assembly/src/scripts/shutdown.sh
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/src/scripts/shutdown.sh?rev=331820&view=auto
==============================================================================
--- geronimo/trunk/modules/assembly/src/scripts/shutdown.sh (added)
+++ geronimo/trunk/modules/assembly/src/scripts/shutdown.sh Tue Nov  8 05:47:28 2005
@@ -0,0 +1,58 @@
+#!/bin/sh
+#
+#  Copyright 2005 The Apache Software Foundation
+# 
+#   Licensed 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.
+
+# --------------------------------------------------------------------
+# $Rev$ $Date$
+# --------------------------------------------------------------------
+
+ARGS=
+
+if [ -z "$JAVA_HOME" ]; then
+    JAVA=`which java`
+    if [ -z "$JAVA" ]; then
+        echo "Unable to locate Java binary. Please add it to the PATH."
+        exit 1
+    fi
+    JAVA_BIN=`dirname $JAVA`
+    JAVA_HOME=$JAVA_BIN/..
+fi
+
+JAVA=$JAVA_HOME/bin/java
+if [ ! -f "$JAVA" ]; then 
+    echo "Unable to locate Java"
+    exit 1
+fi
+
+PRG="$0"
+while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '.*/.*' > /dev/null; then
+        PRG="$link"
+    else
+        PRG=`dirname "$PRG"`/"$link"
+    fi
+done
+
+PRGDIR=`dirname "$PRG"`
+SHUTDOWN_JAR=$PRGDIR/shutdown.jar
+
+if [ ! -f "$SHUTDOWN_JAR" ]; then 
+    echo "Unable to locate the $SHUTDOWN_JAR jar"
+    exit 1
+fi
+
+$JAVA $ARGS -jar $SHUTDOWN_JAR "$@"

Added: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/ShutdownBootstrap.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/ShutdownBootstrap.java?rev=331820&view=auto
==============================================================================
--- geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/ShutdownBootstrap.java (added)
+++ geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/ShutdownBootstrap.java Tue Nov  8 05:47:28 2005
@@ -0,0 +1,89 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.deployment;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.jar.Attributes;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+public class ShutdownBootstrap {
+
+	private String shutdownJar;
+
+	private String shutdownClassPath;
+
+	public String getShutdownJar() {
+		return shutdownJar;
+	}
+
+	public void setShutdownJar(String shutdownJar) {
+		this.shutdownJar = shutdownJar;
+	}
+
+	public String getShutdownClassPath() {
+		return shutdownClassPath;
+	}
+
+	public void setShutdownClassPath(String shutdownClassPath) {
+		this.shutdownClassPath = shutdownClassPath;
+	}
+
+	public void bootstrap() throws Exception {
+		ClassLoader oldCL = Thread.currentThread().getContextClassLoader();
+		try {
+			Thread.currentThread().setContextClassLoader(
+					Bootstrap.class.getClassLoader());
+			Manifest manifest = new Manifest();
+			Attributes mainAttributes = manifest.getMainAttributes();
+			mainAttributes.putValue(
+					Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
+			mainAttributes.putValue(Attributes.Name.MAIN_CLASS.toString(),
+					"org.apache.geronimo.deployment.cli.StopServer");
+			mainAttributes.putValue(Attributes.Name.CLASS_PATH.toString(),
+					shutdownClassPath);
+			createJar(manifest, new File(shutdownJar));
+		} finally {
+			Thread.currentThread().setContextClassLoader(oldCL);
+		}
+	}
+
+	private void createJar(Manifest manifest, File destinationFile)
+			throws IOException {
+		JarOutputStream out = null;
+		try {
+			if (manifest != null) {
+				out = new JarOutputStream(
+						new FileOutputStream(destinationFile), manifest);
+				// add the startup file which allows us to locate the startup
+				// directory
+				out.putNextEntry(new ZipEntry("META-INF/startup-jar"));
+				out.closeEntry();
+			} else {
+				out = new JarOutputStream(new FileOutputStream(destinationFile));
+			}
+		} finally {
+			if (out != null) {
+				out.close();
+			}
+		}
+	}
+
+}

Added: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/StopServer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/StopServer.java?rev=331820&view=auto
==============================================================================
--- geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/StopServer.java (added)
+++ geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/StopServer.java Tue Nov  8 05:47:28 2005
@@ -0,0 +1,178 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed 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.geronimo.deployment.cli;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.MalformedURLException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServerConnection;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+import javax.naming.Context;
+
+import org.apache.geronimo.deployment.cli.ServerConnection.PasswordPrompt;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.jmx.KernelDelegate;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StopServer {
+
+	public static final String RMI_NAMING_CONFG_ID = "org/apache/geronimo/RMINaming";
+
+	public static final String DEFAULT_PORT = "1099";
+
+	String port;
+
+	String user;
+
+	String password;
+
+	private String[] args;
+
+	public static void main(String[] args) {
+		StopServer cmd = new StopServer();
+		cmd.execute(args);
+	}
+
+	public void execute(String args[]) {
+
+		this.args = args;
+
+		int i = 0;
+		while (i < args.length && args[i].startsWith("--")) {
+			if (setParam(i++)) {
+				i++;
+			}
+		}
+		
+		if(i < args.length) {
+			//There was an argument error somewhere.
+			printUsage();
+		}
+
+		try {
+			if (port != null) {
+				Integer.parseInt(port);
+			}
+		} catch (NumberFormatException e) {
+			System.out.println("Invalid port number specified.");
+			System.exit(1);
+		}
+
+		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out),
+				true);
+		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+		try {
+			if (user == null) {
+				out.print("Username: ");
+				out.flush();
+				user = in.readLine();
+			}
+			if (password == null) {
+				password = new PasswordPrompt("Password: ", out)
+						.getPassword(in);
+			}
+		} catch (IOException e) {
+			System.out.println("Unable to prompt for login.");
+			System.exit(1);
+		}
+
+		try {
+			if (port == null) {
+				port = DEFAULT_PORT;
+			}
+			System.out.println("Shutting down Geronimo server on port " + port);
+			Kernel kernel = getRunningKernel();
+			if (kernel != null) {
+				kernel.shutdown();
+				System.out.println("Geronimo server shutdown completed.");
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	private boolean argumentHasValue(int i) {
+		return i + 1 < args.length && !args[i + 1].startsWith("--");
+	}
+
+	private boolean setParam(int i) {
+		if (argumentHasValue(i)) {
+			if (args[i].equals("--user")) {
+				user = args[++i];
+			} else if (args[i].equals("--password")) {
+				password = args[++i];
+			} else if (args[i].equals("--port")) {
+				port = args[++i];
+			} else {
+				printUsage();
+			}
+			return true;
+		} else {
+			printUsage();
+		}
+		return false;
+	}
+
+	public Kernel getRunningKernel() {
+		Map map = new HashMap();
+		map.put("jmx.remote.credentials", new String[] { user, password });
+		map.put(Context.INITIAL_CONTEXT_FACTORY,
+				"com.sun.jndi.rmi.registry.RegistryContextFactory");
+		map.put(Context.PROVIDER_URL, "rmi://localhost:" + port);
+		Kernel kernel = null;
+		try {
+			JMXServiceURL address = new JMXServiceURL(
+					"service:jmx:rmi:///jndi/rmi://localhost" + ":" + port
+							+ "/JMXConnector");
+			JMXConnector jmxConnector = JMXConnectorFactory.connect(address,
+					map);
+			MBeanServerConnection mbServerConnection = jmxConnector
+					.getMBeanServerConnection();
+			kernel = new KernelDelegate(mbServerConnection);
+
+		} catch (MalformedURLException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			System.out
+					.println("Could not communicate with the server.  The server may already be shutdown or the port number may be specified incorrectly.");
+		}
+		return kernel;
+	}
+
+	public void printUsage() {
+		System.out.println();
+		System.out.println("Command-line shutdown syntax:");
+		System.out.println("    shutdown [options]");
+		System.out.println();
+		System.out.println("The available options are:");
+		System.out.println("    --user");
+		System.out.println("    --password");
+		System.out.println("    --port");
+		System.exit(1);
+	}
+
+}