geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r567821 - in /geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main: groovy/org/apache/geronimo/commands/ resources/org/apache/geronimo/commands/
Date Mon, 20 Aug 2007 20:31:28 GMT
Author: jdillon
Date: Mon Aug 20 13:31:26 2007
New Revision: 567821

URL: http://svn.apache.org/viewvc?rev=567821&view=rev
Log:
Hooked up background bits and validation

Added:
    geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ProcessLauncher.groovy
  (with props)
Modified:
    geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java
    geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy
    geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/resources/org/apache/geronimo/commands/StartServerCommandMessages.properties

Modified: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java?rev=567821&r1=567820&r2=567821&view=diff
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java
(original)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java
Mon Aug 20 13:31:26 2007
@@ -30,7 +30,7 @@
 /**
  * Custom AntBuilder to hook up to desired logging muck.
  *
- * @version $Id$
+ * @version $Rev$ $Date$
  */
 public class AntBuilder
     extends groovy.util.AntBuilder

Added: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ProcessLauncher.groovy
URL: http://svn.apache.org/viewvc/geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ProcessLauncher.groovy?rev=567821&view=auto
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ProcessLauncher.groovy
(added)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ProcessLauncher.groovy
Mon Aug 20 13:31:26 2007
@@ -0,0 +1,123 @@
+/*
+ * 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.geronimo.commands
+
+import java.util.Timer
+
+import org.apache.commons.lang.time.StopWatch
+
+import org.apache.commons.logging.Log
+import org.apache.commons.logging.LogFactory
+
+/**
+ * Helper to execute a process and perform some verification logic to determine if the process
is up or not.
+ *
+ * @version $Rev$ $Date$
+ */
+class ProcessLauncher
+{
+    private Log log = LogFactory.getLog(this.class)
+    
+    String name
+    
+    Closure process
+    
+    Closure verifier
+    
+    int verifyWaitDelay = 1000
+    
+    int timeout = -1
+    
+    boolean background = false
+    
+    def launch() {
+        assert process
+        assert name
+        
+        //
+        // FIXME: Can probably just use a Throwable local here
+        //
+        def errors = []
+        
+        def runner = {
+            try {
+                process()
+            }
+            catch (Exception e) {
+                errors << e
+            }
+        }
+        
+        def t = new Thread(runner, "$name Runner")
+        
+        log.info("Launching $name")
+        
+        def watch = new StopWatch()
+        watch.start()
+        
+        t.start()
+        
+        if (verifier) {
+            def timer = new Timer("$name Timer", true)
+            
+            def timedOut = false
+            
+            def timeoutTask
+            if (timeout > 0) {
+                timeoutTask = timer.runAfter(timeout * 1000, {
+                    timedOut = true
+                })
+            }
+            
+            def started = false
+            
+            log.debug("Waiting for ${name}...")
+            
+            while (!started) {
+                if (timedOut) {
+                    throw new Exception("Unable to verify if $name was started in the given
time ($timeout seconds)")
+                }
+                
+                if (errors) {
+                    throw new Exception("Failed to start: $name", errors[0])
+                }
+                
+                if (verifier()) {
+                    started = true
+                }
+                else {
+                    Thread.sleep(verifyWaitDelay)
+                }
+            }
+            
+            timeoutTask?.cancel()
+        }
+        
+        log.info("$name started in $watch")
+        
+        if (!background) {
+            log.debug("Waiting for $name to shutdown...")
+            
+            t.join()
+            
+            log.debug("$name has shutdown")
+        }
+    }
+}

Propchange: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ProcessLauncher.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ProcessLauncher.groovy
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ProcessLauncher.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy
URL: http://svn.apache.org/viewvc/geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy?rev=567821&r1=567820&r2=567821&view=diff
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy
(original)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy
Mon Aug 20 13:31:26 2007
@@ -27,6 +27,7 @@
 import org.apache.commons.cli.OptionBuilder
 import org.apache.commons.cli.Options
 
+// Make sure we use our custom builder
 import org.apache.geronimo.commands.AntBuilder
 
 /**
@@ -45,17 +46,27 @@
     
     File logFile
     
+    boolean background = false
+    
     boolean quiet = false
 
     int verbose = 0
     
     int timeout = -1
     
-    Map properties = [:]
+    final Map properties = [:]
+    
+    final List javaFlags = []
+    
+    final List startModules = []
+    
+    String hostname = 'localhost'
+    
+    int port = 1099
     
-    List javaFlags = []
+    String username = 'system'
     
-    List startModules = []
+    String password = 'manager'
     
     StartServerCommand() {
         super('start-server')
@@ -125,10 +136,14 @@
             .withArgName('name')
             .create('m'))
         
+        options.addOption(OptionBuilder.withLongOpt('background')
+            .withDescription(messages.getMessage('cli.option.background'))
+            .create('b'))
+        
         return options
     }
     
-    protected boolean processCommandLine(CommandLine line) throws CommandException {
+    protected boolean processCommandLine(final CommandLine line) throws CommandException
{
         assert line
         
         def args = line.args
@@ -212,6 +227,10 @@
             }
         }
         
+        if (line.hasOption('b')) {
+            background = true
+        }
+        
         return false
     }
     
@@ -246,137 +265,93 @@
         }
         log.debug("Geronimo home: $geronimoHome")
         
-        ant.java(jar: "$geronimoHome/bin/server.jar", dir: geronimoHome, failonerror: true,
fork: true) {
-            def node = current.wrapper
-            
-            if (timeout > 0) {
-                log.info("Timeout after: ${timeout} seconds")
-                node.setAttribute('timeout', "${timeout * 1000}")
-            }
-            
-            if (logFile) {
-                log.info("Redirecting output to: $logFile")
-                logFile.parentFile.mkdirs()
-                redirector(output: logFile)
-            }
-            
-            if (javaVirtualMachine) {
-                if (!javaVirtualMachine.exists()) {
-                    fail("Java virtual machine is not valid: $javaVirtualMachine")
+        // Setup default java flags
+        if (javaAgentJar) {
+            javaFlags << "-javaagent:${javaAgentJar.canonicalPath}"
+        }
+        
+        // Setup the default properties required to boot the server
+        properties['org.apache.geronimo.base.dir'] = geronimoHome
+        properties['java.io.tmpdir'] = 'var/temp' // Use relative path
+        properties['java.endorsed.dirs'] = prefixSystemPath('java.endorsed.dirs', new File(geronimoHome,
'lib/endorsed'))
+        properties['java.ext.dirs'] = prefixSystemPath('java.ext.dirs', new File(geronimoHome,
'lib/ext'))
+        
+        //
+        // TODO: Add rc script muck here...
+        //
+        
+        def launcher = new ProcessLauncher(name: 'Geronimo Server', background: background)
+        
+        launcher.process = {
+            ant.java(jar: "$geronimoHome/bin/server.jar", dir: geronimoHome, failonerror:
true, fork: true) {
+                def node = current.wrapper
+                
+                if (timeout > 0) {
+                    log.info("Timeout after: ${timeout} seconds")
+                    node.setAttribute('timeout', "${timeout * 1000}")
                 }
                 
-                log.info("Using Java virtual machine: $javaVirtualMachine")
-                node.setAttribute('jvm', javaVirtualMachine)
-            }
-            
-            if (javaAgentJar) {
-                javaFlags << "-javaagent:${javaAgentJar.canonicalPath}"
-            }
-            
-            javaFlags.each {
-                jvmarg(value: it)
-            }
-            
-            // Setup the default properties required to boot the server
-            properties['org.apache.geronimo.base.dir'] = geronimoHome
-            properties['java.io.tmpdir'] = 'var/temp' // Use relative path
-            properties['java.endorsed.dirs'] = prefixSystemPath('java.endorsed.dirs', new
File(geronimoHome, 'lib/endorsed'))
-            properties['java.ext.dirs'] = prefixSystemPath('java.ext.dirs', new File(geronimoHome,
'lib/ext'))
-            
-            properties.each { key, value ->
-                sysproperty(key: key, value: value)
-            }
-            
-            if (quiet) {
-                arg(value: '--quiet')
-            }
-            else {
-                arg(value: '--long')
-            }
-            
-            if (verbose == 1) {
-                arg(value: '--verbose')
-            }
-            else if (verbose > 1) {
-                arg(value: '--veryverbose')
-            }
-            
-            if (startModules) {
-                log.info('Overriding the set of modules to be started')
+                if (logFile) {
+                    log.info("Redirecting output to: $logFile")
+                    logFile.parentFile.mkdirs()
+                    redirector(output: logFile)
+                }
                 
-                arg(value: '--override')
+                if (javaVirtualMachine) {
+                    if (!javaVirtualMachine.exists()) {
+                        fail("Java virtual machine is not valid: $javaVirtualMachine")
+                    }
+                    
+                    log.info("Using Java virtual machine: $javaVirtualMachine")
+                    node.setAttribute('jvm', javaVirtualMachine)
+                }
                 
-                startModules.each {
-                    arg(value: it)
+                javaFlags.each {
+                    jvmarg(value: it)
+                }
+                
+                properties.each { key, value ->
+                    sysproperty(key: key, value: value)
+                }
+                
+                if (quiet) {
+                    arg(value: '--quiet')
+                }
+                else {
+                    arg(value: '--long')
+                }
+                
+                if (verbose == 1) {
+                    arg(value: '--verbose')
+                }
+                else if (verbose > 1) {
+                    arg(value: '--veryverbose')
+                }
+                
+                if (startModules) {
+                    log.info('Overriding the set of modules to be started')
+                    
+                    arg(value: '--override')
+                    
+                    startModules.each {
+                        arg(value: it)
+                    }
                 }
             }
         }
         
-        return Command.SUCCESS
-    }
-    
-    /*
-    void execute() {
-        log.info('Starting Geronimo server...')
-        
-        // Start the server in a seperate thread
-        def t = new Thread(runner, 'Geronimo Server Runner')
-        def watch = new StopWatch()
-        watch.start()
-        t.start()
-        
-        log.info('Waiting for Geronimo server...')
-        
-        def timer = new Timer(true)
-        def verifyTimedOut = false
-        
-        def timeoutTask = {
-            verifyTimedOut = true
-        }
-
-        if (verifyTimeout > 0) {
-            log.debug("Starting verify timeout task triggers in: $verifyTimeout seconds")
-            timer.schedule(timeoutTask, verifyTimeout * 1000)
-        }
-
-        // Verify server started
         def server = new ServerProxy(hostname, port, username, password)
-        def started = false
         
-        while (!started) {
-            if (verifyTimedOut.set) {
-                fail("Unable to verify if the server was started in the given time ($verifyTimeout
seconds)")
-            }
-
-            if (errors) {
-                fail('Failed to start Geronimo server', errors[0])
-            }
-
-            started = server.fullyStarted
-
-            if (!started) {
-                def error = server.lastError
-                if (!error) {
-                    log.debug('Server query failed ignoring', error)
-                }
-
-                Thread.sleep(1000)
-            }
-        }
-
-        // Stop the timer, server should be up now
-        timeoutTask.cancel()
-
-        log.info("Geronimo server started in $watch")
-
-        if (!background) {
-            log.info('Waiting for Geronimo server to shutdown...')
-            t.join()
+        launcher.verifier = {
+            return server.fullyStarted
         }
+        
+        launcher.launch()
+        
+        return Command.SUCCESS
     }
-    */
     
-    private String prefixSystemPath(String name, File file) {
+    private String prefixSystemPath(final String name, final File file) {
         assert name
         assert file
 

Modified: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/resources/org/apache/geronimo/commands/StartServerCommandMessages.properties
URL: http://svn.apache.org/viewvc/geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/resources/org/apache/geronimo/commands/StartServerCommandMessages.properties?rev=567821&r1=567820&r2=567821&view=diff
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/resources/org/apache/geronimo/commands/StartServerCommandMessages.properties
(original)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/resources/org/apache/geronimo/commands/StartServerCommandMessages.properties
Mon Aug 20 13:31:26 2007
@@ -47,6 +47,8 @@
 
 cli.option.module=Start up a specific module by name.
 
+cli.option.background=Run the server process in the background.
+
 ##
 ## Option usage (help)
 ##



Mime
View raw message