You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2008/04/23 19:31:24 UTC

svn commit: r650946 - in /ofbiz/trunk/framework/appserver: config/appserver.properties src/org/ofbiz/appservers/GenerateContainer.java templates/wasce2/geronimo-application.xml

Author: jleroux
Date: Wed Apr 23 10:31:16 2008
New Revision: 650946

URL: http://svn.apache.org/viewvc?rev=650946&view=rev
Log:
If present GERONIMO_HOME env var is no longer overloaded  by appserver.properties geronimoHome value (It was done the wrong side since env vars are platform dependent for sure and not properties)
Better handling of processes ends (added finally to try blocks)
Redeployment is now possible
General refactoring of GenerateContainer.java
POS related JARs are no longer put in geronimo repository

Modified:
    ofbiz/trunk/framework/appserver/config/appserver.properties
    ofbiz/trunk/framework/appserver/src/org/ofbiz/appservers/GenerateContainer.java
    ofbiz/trunk/framework/appserver/templates/wasce2/geronimo-application.xml

Modified: ofbiz/trunk/framework/appserver/config/appserver.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/appserver/config/appserver.properties?rev=650946&r1=650945&r2=650946&view=diff
==============================================================================
--- ofbiz/trunk/framework/appserver/config/appserver.properties (original)
+++ ofbiz/trunk/framework/appserver/config/appserver.properties Wed Apr 23 10:31:16 2008
@@ -21,31 +21,36 @@
 ######## Default WASCE/Geronimo Settings. Refer to the Guidelines in the OFBiz documentation : http://docs.ofbiz.org/x/Ah ########
 ### Path to geronimo home (in other words, application server location).
 # You may also use a GERONIMO_HOME env var, in such case let commented out here
-#Linux
+### Linux
 #geronimoHome=/home/jacques/IBM/WebSphere/AppServerCommunityEdition
 #geronimoHome=/home/jacques/Apache Software Foundation/geronimo-tomcat6-jee5-2.0.3
-# Windows *** Note that under Windows you must use / here in place of \ (or put \\) ***
+### Windows *** Note that under Windows you must use / here in place of \ (or put \\) ***
 #geronimoHome=C:/Program Files/IBM/WebSphere/AppServerCommunityEdition
-#geronimoHome=C:/Program Files/Apache Software Foundation/geronimo-tomcat6-jee5-2.0.3
+# Beware for geronimo-2.0.3 snapshot, under Windows some files have a path longer than 256 chars. Hence I put it directly under c:
+#geronimoHome=C:/geronimo-tomcat6-jee5-2.0.3 
 
 ### user login
 user=system
 # password
 password=manager
 
-### Server is offline or not (should be ofline the 1st time you deploy since you need to copy after lines from META-INF/REAME)
-offline=true
+### Server is offline or not. Should be offline the 1st time you deploy since you need to copy after lines from META-INF/REAME hence by default true
+offline=ftrue
 
 ### Pause in deployment script ?
-pauseInGeronimoScript=false
+pauseInGeronimoScript=ftrue
 
-### host
-#host=192.168.2.7
-
-### port
-#port=1099
+### Undeploy/Deploy (useful when offline) or Redeploy (implies that the server is running)
+redeploy=ftrue
 
 ### The number (instancesNumber) given here is in origin 0. Hence 0 means one instance.
 # In other word you give the n-1 number of instances (n being the number of instances).
 # For instance 2 means 3 instances deployed. # This to allow the default instance which is not numbered
 instancesNumber=0
+
+### host
+#host=192.168.2.7
+#geronimoHostHome=C/Program Files/IBM/WebSphere/AppServerCommunityEdition
+
+### port
+#port=31099

Modified: ofbiz/trunk/framework/appserver/src/org/ofbiz/appservers/GenerateContainer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/appserver/src/org/ofbiz/appservers/GenerateContainer.java?rev=650946&r1=650945&r2=650946&view=diff
==============================================================================
--- ofbiz/trunk/framework/appserver/src/org/ofbiz/appservers/GenerateContainer.java (original)
+++ ofbiz/trunk/framework/appserver/src/org/ofbiz/appservers/GenerateContainer.java Wed Apr 23 10:31:16 2008
@@ -87,13 +87,16 @@
      * @see org.ofbiz.base.container.Container#init(java.lang.String[], java.lang.String)
      */
     public void init(String[] args, String configFile) {
-        this.ofbizHome = System.getProperty("ofbiz.home");
-        this.configFile = configFile;
+        ofbizHome = System.getProperty("ofbiz.home");
+        configFile = configFile;
         this.args = args;
-        this.isGeronimo = args[0].toLowerCase().contains("geronimo") || args[0].toLowerCase().contains("wasce");
-        if (this.isGeronimo) {
-            this.target="/META-INF/";
-            this.geronimoHome = UtilProperties.getPropertyValue("appserver", "geronimoHome", null);
+        isGeronimo = args[0].toLowerCase().contains("geronimo") || args[0].toLowerCase().contains("wasce");
+        if (isGeronimo) {
+            target="/META-INF/";
+            geronimoHome = System.getenv("GERONIMO_HOME");
+            if (geronimoHome == null) {
+                geronimoHome = UtilProperties.getPropertyValue("appserver", "geronimoHome", null);
+            }            
         }
     }
 
@@ -101,7 +104,7 @@
      * @see org.ofbiz.base.container.Container#start()
      */
     public boolean start() throws ContainerException {
-        this.generateFiles();
+        generateFiles();
         System.exit(1);
         return true;
     }
@@ -116,36 +119,55 @@
     }
 
     private void generateFiles() throws ContainerException {
+        if (isGeronimo) {
+            if (geronimoHome == null) {
+                Debug.logFatal("*** 'GERONIMO_HOME' was not found in your environment. Please set the location of Geronimo into a GERONIMO_HOME env var or as a geronimoHome property in appserver.properties file.", module);
+                throw new ContainerException("Error in Geronimo deployment, please check the log");
+            }
+        }
         File files[] = getTemplates();
         Map<String, Object> dataMap = buildDataMap();
 
         String user = UtilProperties.getPropertyValue("appserver", "user", "system");
         String password = UtilProperties.getPropertyValue("appserver", "password", "manager");
-        int instancesNumber = (int) UtilProperties.getPropertyNumber("appserver", "instancesNumber");
+
         boolean offline = UtilProperties.propertyValueEqualsIgnoreCase("appserver", "offline", "true");
+        boolean redeploy = UtilProperties.propertyValueEqualsIgnoreCase("appserver", "redeploy", "true");
+
+        String geronimoHostHome = UtilProperties.getPropertyValue("appserver", "geronimoHostHome", null);
         String host = UtilProperties.getPropertyValue("appserver", "host", "");
         String port = UtilProperties.getPropertyValue("appserver", "port", "");
         boolean pauseInGeronimoScript = UtilProperties.propertyValueEqualsIgnoreCase("appserver", "pauseInGeronimoScript", "true");
+
+        int instancesNumber = (int) UtilProperties.getPropertyNumber("appserver", "instancesNumber");
         String instanceNumber = "";
 
         if (isGeronimo) {
-            if (geronimoHome == null) {
-                geronimoHome = System.getenv("GERONIMO_HOME");
-                if (geronimoHome == null) {
-                    Debug.logFatal("'GERONIMO_HOME' was not found in your environment. Please set the location of Geronimo into a GERONIMO_HOME env var or as a geronimoHome property in setup.properties file.", module);
+            File geronimoHomeDir = new File (geronimoHome);
+            if (!(geronimoHomeDir.isDirectory())) {
+                Debug.logFatal("*** " + geronimoHome + " does not exist or is not a directoy. Please set the location of Geronimo into a GERONIMO_HOME env var or as a geronimoHome property in appserver.properties file.", module);
+                throw new ContainerException("Error in Geronimo deployment, please check the log");
+            }
+
+            if (UtilValidate.isNotEmpty(host) && UtilValidate.isNotEmpty(geronimoHostHome)) {
+                geronimoHomeDir = new File ("//" + host + "/" + geronimoHostHome);
+                if (!(geronimoHomeDir.isDirectory())) {
+                    Debug.logFatal("*** " + geronimoHostHome + " does not exist or is not a directoy. Please set the location of Geronimo on host as a geronimoHostHome property in appserver.properties file.", module);
                     throw new ContainerException("Error in Geronimo deployment, please check the log");
                 }
+            } else {
+                geronimoHostHome = geronimoHome;
             }
-                File geronimoHomeDir = new File (geronimoHome);
-                if (! (geronimoHomeDir.isDirectory())) {
-                    Debug.logFatal(geronimoHome + " does not exist or is not a directoy. Please set the location of Geronimo into a GERONIMO_HOME env var or as a geronimoHome property in setup.properties file.", module);
+
+            if (redeploy && offline) {
+                Debug.logFatal("*** You can't use redeploy with a server offline.", module);
                     throw new ContainerException("Error in Geronimo deployment, please check the log");
                 }
 
             for(int inst = 0; inst <= instancesNumber; inst++) {
                 instanceNumber = (inst == 0 ? "" : inst).toString();
                 GenerateGeronimoDeployment geronimoDeployment = new GenerateGeronimoDeployment();
-                List classpathJars = geronimoDeployment.generate(args[0], geronimoHome, instanceNumber);
+                List classpathJars = geronimoDeployment.generate(args[0], geronimoHostHome, instanceNumber);
                 if (classpathJars == null) {
                     throw new ContainerException("Error in Geronimo deployment, please check the log");
                 }
@@ -225,45 +247,48 @@
 
                 String ofbizName = "ofbiz" + instanceNumber;
                 String separator = File.separator;
-                String geronimoBin = geronimoHome + separator + "bin";
-                File workingDir = new File(geronimoBin);
-                ProcessBuilder pb = null;
+                File workingDir = new File(geronimoHome + separator + "bin");
+                ProcessBuilder processBuilder = null;
+                Process process = null;
                 String command = null;
                 String commandCommonPart = null;
-                String commandCommonHostPart = "";
+                if ("\\".equals(separator)) {   //Windows
+                    commandCommonPart = "deploy --user " + user +  " --password " +  password;
+                } else {                        // Linux
+                    commandCommonPart = workingDir + "/deploy.sh --user " + user +  " --password " +  password;
+                }
                 if (UtilValidate.isNotEmpty(host)) {
-                    commandCommonHostPart = " --host" + host + (UtilValidate.isNotEmpty(port) ? port : "");
+                    commandCommonPart += " --host " + host + (UtilValidate.isNotEmpty(port) ? " --port " + port : "");
                 }
 
+                if (!redeploy) {
                 if ("\\".equals(separator)) { //Windows
-                    commandCommonPart = "deploy --user " + user +  " --password " +  password + commandCommonHostPart;
                     if (offline) {
                         command = commandCommonPart + " --offline undeploy " + ofbizName;
                     } else {
                         command = commandCommonPart + " undeploy " + ofbizName;
                     }
-                    pb = new ProcessBuilder("cmd.exe", "/c", command);
+                        processBuilder = new ProcessBuilder("cmd.exe", "/c", command);
                 } else {                        // Linux
-                    commandCommonPart = workingDir + "/deploy.sh --user " + user +  " --password " +  password + commandCommonHostPart;
                     if (offline) {
                         command = commandCommonPart + " --offline undeploy " + ofbizName;
                     } else {
                         command = commandCommonPart + " undeploy " + ofbizName;
                     }
-                    pb = new ProcessBuilder("sh", "-c", command);
+                        processBuilder = new ProcessBuilder("sh", "-c", command);
                 }
 
                 if (pauseInGeronimoScript) {
-                    Map<String, String> env = pb.environment();
+                        Map<String, String> env = processBuilder.environment();
                     env.put("GERONIMO_BATCH_PAUSE", "on");
                 }
-                pb.directory(workingDir);
+                    processBuilder.directory(workingDir);
                 
                 try {
                     System.out.println("Currently undeploying " + ofbizName + ", using : <<" + command + ">>, please wait ...");
-                    pb.redirectErrorStream(true);
-                    Process p = pb.start();
-                    java.io.InputStream is = p.getInputStream();
+                        processBuilder.redirectErrorStream(true);
+                        process = processBuilder.start();
+                        java.io.InputStream is = process.getInputStream();
                     byte[] buf = new byte[2024];
                     int readLen = 0;
                     while((readLen = is.read(buf,0,buf.length)) != -1) {
@@ -274,43 +299,57 @@
                         }
                     }
                     is.close();
-                    p.waitFor();
-                    //                    System.out.println(p.waitFor());
-                    //                    System.out.println("exit value" + p.exitValue());
+                        process.waitFor();
+    //                    System.out.println(process.waitFor());
+    //                    System.out.println("exit value" + process.exitValue());
                     Debug.logInfo(ofbizName + " undeployment ended" , module);
                 } catch (IOException e) {
                     throw new ContainerException(e);
                 } catch (InterruptedException e) {
                     throw new ContainerException(e);
+                    } finally {
+                        process.destroy();
+                    }
                 }
 
+                if (redeploy) {
+                    if ("\\".equals(separator)) { //Windows
+                        command = commandCommonPart + " redeploy " + ofbizHome;
+                        processBuilder = new ProcessBuilder("cmd.exe", "/c", command);
+                    } else {                      // Linux
+                        command = commandCommonPart + " redeploy " + ofbizHome;
+                        processBuilder = new ProcessBuilder("sh", "-c", command);
+                }
+
+                } else {
                 if ("\\".equals(separator)) { //Windows
                     if (offline) {
-                        command = "deploy --user " + user +  " --password " +  password + " --offline deploy --inPlace " + ofbizHome;
+                            command = commandCommonPart + " --offline deploy --inPlace " + ofbizHome;
                     } else {
-                        command = "deploy --user " + user +  " --password " +  password + " deploy --inPlace " + ofbizHome;
+                            command = commandCommonPart + " deploy --inPlace " + ofbizHome;
                     }
-                    pb = new ProcessBuilder("cmd.exe", "/c", command);
+                        processBuilder = new ProcessBuilder("cmd.exe", "/c", command);
                 } else {                      // Linux
                     if (offline) {
-                        command = workingDir + "/deploy.sh --user " + user +  " --password " +  password + " --offline deploy --inPlace " + ofbizHome;
+                            command = commandCommonPart + " --offline deploy --inPlace " + ofbizHome;
                     } else {
-                        command = workingDir + "/deploy.sh --user " +  user +  " --password " +  password + " deploy --inPlace " + ofbizHome;
+                            command = commandCommonPart + " deploy --inPlace " + ofbizHome;
+                        }
+                        processBuilder = new ProcessBuilder("sh", "-c", command);
                     }
-                    pb = new ProcessBuilder("sh", "-c", command);
                 }
 
                 if (pauseInGeronimoScript) {
-                    Map<String, String> env = pb.environment();
+                    Map<String, String> env = processBuilder.environment();
                     env.put("GERONIMO_BATCH_PAUSE", "on");
                 }
-                pb.directory(workingDir);
+                processBuilder.directory(workingDir);
                 
                 try {
                     System.out.println("Currently deploying " + ofbizName + ", using : <<" + command + ">>, please wait ...");
-                    pb.redirectErrorStream(true);
-                    Process p = pb.start();
-                    java.io.InputStream is = p.getInputStream();
+                    processBuilder.redirectErrorStream(true);
+                    process = processBuilder.start();
+                    java.io.InputStream is = process.getInputStream();
                     byte[] buf = new byte[2024];
                     int readLen = 0;
                     while((readLen = is.read(buf,0,buf.length)) != -1) {
@@ -321,14 +360,16 @@
                         }
                     }
                     is.close();
-                    p.waitFor();
-                    //                    System.out.println(p.waitFor());
-                    //                    System.out.println("exit value" + p.exitValue());
+                    process.waitFor();
+//                    System.out.println(process.waitFor());
+//                    System.out.println("exit value" + process.exitValue());
                     Debug.logInfo(ofbizName + " deployment ended" , module);
                 } catch (IOException e) {
                     throw new ContainerException(e);
                 } catch (InterruptedException e) {
                     throw new ContainerException(e);
+                } finally {
+                    process.destroy();
                 }
             }
         } else {

Modified: ofbiz/trunk/framework/appserver/templates/wasce2/geronimo-application.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/appserver/templates/wasce2/geronimo-application.xml?rev=650946&r1=650945&r2=650946&view=diff
==============================================================================
--- ofbiz/trunk/framework/appserver/templates/wasce2/geronimo-application.xml (original)
+++ ofbiz/trunk/framework/appserver/templates/wasce2/geronimo-application.xml Wed Apr 23 10:31:16 2008
@@ -58,7 +58,7 @@
         <#if location.contains("/applications/")>
             <#assign location = location.substring(location.lastIndexOf("applications"))/>
         </#if>
-        <#if location.contains("/specialpurpose/")>
+        <#if location.contains("/specialpurpose/") && !location.contains("/pos/")>
             <#assign location = location.substring(location.lastIndexOf("specialpurpose"))/>
         </#if>
         <#if location.contains("/hot-deploy/")>