geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r939070 - in /geronimo/server/trunk/framework/modules: geronimo-main/src/main/java/org/apache/geronimo/main/ geronimo-shell-base/src/main/java/org/apache/geronimo/shell/ geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/
Date Wed, 28 Apr 2010 20:04:43 GMT
Author: gawor
Date: Wed Apr 28 20:04:42 2010
New Revision: 939070

URL: http://svn.apache.org/viewvc?rev=939070&view=rev
Log:
GERONIMO-5213: Implement start-server shell command to fork the server process. Might need
to rethink that later on

Removed:
    geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/StartServerstrapper.java
Modified:
    geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java
    geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/BaseCommandSupport.java
    geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/StartClientCommand.java
    geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/StartServerCommand.java
    geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/WaitForServerCommand.java

Modified: geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java?rev=939070&r1=939069&r2=939070&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java
Wed Apr 28 20:04:42 2010
@@ -160,8 +160,10 @@ public class Bootstrapper {
             System.setProperty(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, 
                                String.valueOf(defaultStartLevel));       
                       
-            System.setProperty(org.apache.felix.karaf.main.Main.PROPERTY_USE_LOCK, 
-                               (uniqueStorage) ? "false" : "true");
+            if (System.getProperty(org.apache.felix.karaf.main.Main.PROPERTY_USE_LOCK) ==
null) {
+                System.setProperty(org.apache.felix.karaf.main.Main.PROPERTY_USE_LOCK, 
+                                   (uniqueStorage) ? "false" : "true");
+            }
             
         } catch (IOException e) {
             e.printStackTrace();

Modified: geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/BaseCommandSupport.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/BaseCommandSupport.java?rev=939070&r1=939069&r2=939070&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/BaseCommandSupport.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/BaseCommandSupport.java
Wed Apr 28 20:04:42 2010
@@ -137,12 +137,23 @@ public abstract class BaseCommandSupport
     
     public Kernel getKernel() {
         ServiceReference reference = bundleContext.getServiceReference(Kernel.class.getName());
-        Kernel kernel = getService(Kernel.class, reference);
+        Kernel kernel = null;
+        if (reference != null) {
+            kernel = getService(Kernel.class, reference);
+        }
         return kernel;
     }
     
+    public boolean isEmbedded() {
+        return isEmbedded(getKernel());
+    }
+    
     public boolean isEmbedded(Kernel kernel) {
-        Set deamon = kernel.listGBeans(new AbstractNameQuery("org.apache.geronimo.system.main.EmbeddedDaemon"));
-        return !deamon.isEmpty();
+        if (kernel != null) {
+            Set deamon = kernel.listGBeans(new AbstractNameQuery("org.apache.geronimo.system.main.EmbeddedDaemon"));
+            return !deamon.isEmpty();
+        } else {
+            return false;
+        }        
     }
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/StartClientCommand.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/StartClientCommand.java?rev=939070&r1=939069&r2=939070&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/StartClientCommand.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/StartClientCommand.java
Wed Apr 28 20:04:42 2010
@@ -73,13 +73,13 @@ public class StartClientCommand extends 
         }
                  
         //init properties
-        if(propertyFrom!=null){
-            for(String nameValue:propertyFrom){
+        if (propertyFrom != null) {
+            for(String nameValue : propertyFrom){
                 addPropertyFrom(nameValue, null);
             }
         }
-        if(gPropertyFrom!=null){
-            for(String nameValue:gPropertyFrom){
+        if (gPropertyFrom != null) {
+            for(String nameValue : gPropertyFrom){
                 addPropertyFrom(nameValue, "org.apache.geronimo");
             }
         }

Modified: geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/StartServerCommand.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/StartServerCommand.java?rev=939070&r1=939069&r2=939070&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/StartServerCommand.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/StartServerCommand.java
Wed Apr 28 20:04:42 2010
@@ -19,14 +19,17 @@
 
 package org.apache.geronimo.shell.geronimo;
 
-import java.util.Arrays;
+import java.io.File;
 import java.util.List;
 
 import org.apache.felix.gogo.commands.Command;
 import org.apache.felix.gogo.commands.Option;
-import org.apache.geronimo.cli.CLParserException;
-import org.apache.geronimo.cli.daemon.DaemonCLParser;
-import org.apache.geronimo.main.Bootstrapper;
+import org.apache.tools.ant.ExitStatusException;
+import org.apache.tools.ant.taskdefs.Java;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Environment.Variable;
+
 /**
  * @version $Rev$ $Date$
  */
@@ -58,40 +61,146 @@ public class StartServerCommand extends 
 
      @Override
      protected Object doExecute() throws Exception {
-      // If we are not backgrounding, then add a nice message for the user when ctrl-c gets
hit
-         if (!background) {
-             Runtime.getRuntime().addShutdownHook(new Thread(){
-                 public void run(){
-                     println("Shutting down Server...");
-                   }
-             });
+         if (isEmbedded()) {
+             // do nothing in embedded mode
+             return null;
          }
-        
-        DaemonCLParser parser = getCLParser();
-        try {
-            parser.parse(null);
-        } catch (CLParserException e) {
-            System.err.println(e.getMessage());
-            parser.displayHelp();
-        }
-
-        Bootstrapper boot = createBootstrapper();
-        boot.execute(parser);
-        
-        return null;
+         
+         ant = new AntBuilder(log);
 
-     }
+         if (geronimoHome == null) {
+             geronimoHome = this.bundleContext.getProperty("org.apache.geronimo.home.dir");
+         }
 
-     protected Bootstrapper createBootstrapper() {
-          Bootstrapper boot = new StartServerstrapper(bundleContext,session.getConsole());
-          boot.setWaitForStop(false);
-          boot.setStartBundles(Arrays.asList("org.apache.geronimo.framework/j2ee-system//car"));
-          boot.setLog4jConfigFile("var/log/server-log4j.properties");
-          return (Bootstrapper) boot;
-     }
+         log.debug("Geronimo home: " + geronimoHome);
+
+         // Set the properties which we pass to the JVM from the startup script
+         properties.put("org.apache.geronimo.home.dir", geronimoHome);
+         properties.put("karaf.home", geronimoHome);
+         properties.put("karaf.base", geronimoHome);
+         // Use relative path
+         properties.put("java.io.tmpdir", "var/temp");// Use relative path
+         properties.put("java.endorsed.dirs", prefixSystemPath("java.endorsed.dirs", new
File(geronimoHome, "lib/endorsed")));
+         properties.put("java.ext.dirs", prefixSystemPath("java.ext.dirs", new File(geronimoHome,
"lib/ext")));
+         // set console properties
+         properties.put("karaf.startLocalConsole", "false");
+         properties.put("karaf.startRemoteShell", "true");
+         properties.put("karaf.lock", "false");
+                 
+           // Setup default java flags
+         if (getJavaAgentJar() != null && getJavaAgentJar().exists()) {
+             javaFlags.add("-javaagent:" + getJavaAgentJar().getCanonicalPath());
+         }
+                  
+         //init properties
+         if (propertyFrom != null) {
+             for(String nameValue : propertyFrom){
+                 addPropertyFrom(nameValue, null);
+             }
+         }
+         if (gPropertyFrom != null) {
+             for(String nameValue : gPropertyFrom){
+                 addPropertyFrom(nameValue, "org.apache.geronimo");
+             }
+         }
+
+         final ServerProxy server = new ServerProxy(hostname, port, username, password, secure);
+         
+         ProcessLauncher launcher = new ProcessLauncher(log, "Geronimo Server", background,session.getConsole())
{
+             @Override
+             protected void process() throws Exception {
+                 try {
+                     Java javaTask = (Java) ant.createTask("java");
+                     javaTask.setClassname("org.apache.geronimo.cli.daemon.DaemonCLI");
+                     Path path = javaTask.createClasspath();
+                     File libDir = new File(geronimoHome, "lib");
+                     FileSet fileSet = new FileSet();
+                     fileSet.setDir(libDir);
+                     path.addFileset(fileSet);
+                     javaTask.setDir(new File(geronimoHome));
+                     javaTask.setFailonerror(true);
+                     javaTask.setFork(true);
+                     
+                     if (timeout > 0) {
+                         log.info("Timeout after: " + timeout + " seconds");
+                         javaTask.setTimeout((long) timeout);
+                     }
+
+                     if (logFile != null) {
+                         log.info("Redirecting output to: " + logFile);
+                         File output = new File(logFile);
+                         output.mkdirs();
+                         javaTask.setOutput(output);
+                     }
+
+                     if (javaVirtualMachine != null) {
+                         if (!(new File(javaVirtualMachine).exists())) {
+                             throw new Exception("Java virtual machine is not valid: " +
javaVirtualMachine);
+                         }
+
+                         log.info("Using Java virtual machine: " + javaVirtualMachine);
+                         javaTask.setJvm(javaVirtualMachine);
+                     }
+
+                     if (javaFlags != null) {
+                         for (String javaFlag : javaFlags) {
+                             javaTask.createJvmarg().setValue(javaFlag);
+                         }
+                     }
+                     
+                     for (String i : properties.keySet()) {
+                         Variable sysp = new Variable();
+                         sysp.setKey(i);
+                         sysp.setValue(properties.get(i));
+                         javaTask.addSysproperty(sysp);
+                     }
+
+                     if (quiet) {
+                         javaTask.createArg().setValue("--quiet");
+                     } else {
+                         javaTask.createArg().setValue("--long");
+                     }
+                     
+                     if (verbose) {
+                         javaTask.createArg().setValue("--verbose");
+                     }
+                     
+                     if (startModules != null) {
+                         javaTask.createArg().setValue("--override");
+                         for (String module : startModules) {
+                             javaTask.createArg().setValue(module);
+                         }
+                     }
+                     
+                     javaTask.execute();
+                 } catch (ExitStatusException e) {
+                     String tmp = "";
+                     log.info(tmp);
+
+                     if (e.getStatus() != 0) {
+                         log.warn(tmp);
+                     }
+
+                     tmp = "Process exited with status: " + e.getStatus();
+
+                     throw e;
+                 }
+             }
+             
+             @Override
+             protected boolean verifier() {
+                 if (server.isFullyStarted()) {
+                     server.closeConnection();
+                     return true;
+                 } else {
+                     return false;
+                 }
+             }
+         };
+
+         launcher.launch();
 
-     protected DaemonCLParser getCLParser() {
-          return new DaemonCLParser(System.out);
+         return null;
      }
 
 }

Modified: geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/WaitForServerCommand.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/WaitForServerCommand.java?rev=939070&r1=939069&r2=939070&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/WaitForServerCommand.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-shell-base/src/main/java/org/apache/geronimo/shell/geronimo/WaitForServerCommand.java
Wed Apr 28 20:04:42 2010
@@ -40,18 +40,18 @@ public class WaitForServerCommand extend
     int timeout = 60;
 
     private class TimingTimerTask extends TimerTask {
-        protected TimingTimerTask() {
-            super();
-        }
-
         @Override
         public void run() {
             timedOut = true;
         }
-
     }
 
     protected Object doExecute() throws Exception {
+        if (isEmbedded()) {
+            // do nothing in embedded mode
+            return null;
+        }
+        
         Timer timer = new Timer(true);
 
         TimerTask timeoutTask = new TimingTimerTask();



Mime
View raw message