diff --git a/src/helma/main/ApplicationManager.java b/src/helma/main/ApplicationManager.java index f58ed817..54052fa2 100644 --- a/src/helma/main/ApplicationManager.java +++ b/src/helma/main/ApplicationManager.java @@ -79,7 +79,7 @@ public class ApplicationManager implements XmlRpcHandler { * to create and start new applications. */ protected void checkForChanges() { - if (props.lastModified() > lastModified) { + if (props.lastModified() > lastModified && server.getApplicationsOption() == null) { try { for (Enumeration e = props.keys(); e.hasMoreElements();) { String appName = (String) e.nextElement(); @@ -152,19 +152,27 @@ public class ApplicationManager implements XmlRpcHandler { */ public void startAll() { try { - for (Enumeration e = props.keys(); e.hasMoreElements();) { - String appName = (String) e.nextElement(); - - if (appName.indexOf(".") == -1) { - String appValue = props.getProperty(appName); - - if (appValue != null && appValue.length() > 0) { - appName = appValue; - } - - AppDescriptor desc = new AppDescriptor(appName); + String[] apps = server.getApplicationsOption(); + if (apps != null) { + for (int i = 0; i < apps.length; i++) { + AppDescriptor desc = new AppDescriptor(apps[i]); desc.start(); } + } else { + for (Enumeration e = props.keys(); e.hasMoreElements();) { + String appName = (String) e.nextElement(); + + if (appName.indexOf(".") == -1) { + String appValue = props.getProperty(appName); + + if (appValue != null && appValue.length() > 0) { + appName = appValue; + } + + AppDescriptor desc = new AppDescriptor(appName); + desc.start(); + } + } } for (Enumeration e = descriptors.elements(); e.hasMoreElements();) { diff --git a/src/helma/main/JettyServer.java b/src/helma/main/JettyServer.java index f2745706..d2c41c38 100644 --- a/src/helma/main/JettyServer.java +++ b/src/helma/main/JettyServer.java @@ -27,6 +27,7 @@ import java.util.StringTokenizer; import java.net.URL; import java.net.InetSocketAddress; import java.io.IOException; +import java.io.File; public class JettyServer { @@ -36,11 +37,12 @@ public class JettyServer { // the AJP13 Listener, used for connecting from external webserver to servlet via JK protected AJP13Listener ajp13; - public static JettyServer init(Server server) throws IOException { - if (server.configFile != null && server.configFile.exists()) { - return new JettyServer(server.configFile.toURI().toURL()); - } else if (server.websrvPort != null || server.ajp13Port != null) { - return new JettyServer(server.websrvPort, server.ajp13Port, server); + public static JettyServer init(Server server, ServerConfig config) throws IOException { + File configFile = config.getConfigFile(); + if (configFile != null && configFile.exists()) { + return new JettyServer(configFile.toURI().toURL()); + } else if (config.hasWebsrvPort() || config.hasAjp13Port()) { + return new JettyServer(config.getWebsrvPort(), config.getAjp13Port(), server); } return null; } diff --git a/src/helma/main/Server.java b/src/helma/main/Server.java index 69d1a725..d7074062 100644 --- a/src/helma/main/Server.java +++ b/src/helma/main/Server.java @@ -66,15 +66,9 @@ public class Server implements Runnable { private Vector extensions; private Thread mainThread; - // server ports - InetSocketAddress rmiPort = null; - InetSocketAddress xmlrpcPort = null; - InetSocketAddress websrvPort = null; - InetSocketAddress ajp13Port = null; + // configuration + ServerConfig config; - // Jetty configuration file - File configFile = null; - // map of server-wide database sources Hashtable dbSources; @@ -97,12 +91,11 @@ public class Server implements Runnable { server = this; starttime = System.currentTimeMillis(); - rmiPort = config.getRmiPort(); - xmlrpcPort = config.getXmlrpcPort(); - websrvPort = config.getWebsrvPort(); - ajp13Port = config.getAjp13Port(); + this.config = config; hopHome = config.getHomeDir(); - configFile = config.getConfigFile(); + if (hopHome == null) { + throw new RuntimeException("helma.home property not set"); + } // create system properties sysProps = new ResourceProperties(); @@ -243,6 +236,8 @@ public class Server implements Runnable { config.setHomeDir(new File(args[++i])); } else if (args[i].equals("-f") && ((i + 1) < args.length)) { config.setPropFile(new File(args[++i])); + } else if (args[i].equals("-a") && ((i + 1) < args.length)) { + config.setApps(StringUtils.split(args[++i])); } else if (args[i].equals("-p") && ((i + 1) < args.length)) { try { config.setRmiPort(getInetSocketAddress(args[++i])); @@ -333,8 +328,9 @@ public class Server implements Runnable { System.out.println(""); System.out.println("Usage: java helma.main.Server [options]"); System.out.println("Possible options:"); - System.out.println(" -h dir Specify hop home directory"); - System.out.println(" -f file Specify server.properties file"); + System.out.println(" -a app[,...] Specify applications to start"); + System.out.println(" -h dir Specify hop home directory"); + System.out.println(" -f file Specify server.properties file"); System.out.println(" -c jetty.xml Specify Jetty XML configuration file"); System.out.println(" -w [ip:]port Specify embedded web server address/port"); System.out.println(" -x [ip:]port Specify XML-RPC address/port"); @@ -478,7 +474,7 @@ public class Server implements Runnable { if (sysProps.getProperty("extensions") != null) { initExtensions(); } - jetty = JettyServer.init(this); + jetty = JettyServer.init(this, config); } @@ -562,7 +558,8 @@ public class Server implements Runnable { */ public void run() { try { - if (xmlrpcPort != null) { + if (config.hasXmlrpcPort()) { + InetSocketAddress xmlrpcPort = config.getXmlrpcPort(); String xmlparser = sysProps.getProperty("xmlparser"); if (xmlparser != null) { @@ -591,7 +588,8 @@ public class Server implements Runnable { logger.info("Starting XML-RPC server on port " + (xmlrpcPort)); } - if (rmiPort != null) { + if (config.hasRmiPort()) { + InetSocketAddress rmiPort = config.getRmiPort(); if (paranoid) { HelmaSocketFactory factory = new HelmaSocketFactory(); String rallow = sysProps.getProperty("allowWeb"); @@ -731,6 +729,14 @@ public class Server implements Runnable { return hopHome; } + /** + * Get the explicit list of apps if started with -a option + * @return + */ + public String[] getApplicationsOption() { + return config.getApps(); + } + /** * Get the main Server instance. */ diff --git a/src/helma/main/ServerConfig.java b/src/helma/main/ServerConfig.java index 59899bf5..68364cca 100644 --- a/src/helma/main/ServerConfig.java +++ b/src/helma/main/ServerConfig.java @@ -32,11 +32,16 @@ public class ServerConfig { private File propFile = null; private File homeDir = null; private File configFile = null; + private String[] apps = null; public boolean hasPropFile() { return (propFile != null); } + public boolean hasConfigFile() { + return (configFile != null); + } + public boolean hasHomeDir() { return (homeDir != null); } @@ -57,6 +62,10 @@ public class ServerConfig { return (ajp13Port != null); } + public boolean hasApps() { + return (apps != null); + } + public InetSocketAddress getRmiPort() { return rmiPort; } @@ -112,4 +121,12 @@ public class ServerConfig { public void setConfigFile(File configFile) { this.configFile = configFile == null ? null : configFile.getAbsoluteFile(); } + + public String[] getApps() { + return apps; + } + + public void setApps(String[] apps) { + this.apps = apps; + } } diff --git a/start.bat b/start.bat index 06771c62..84dcde88 100755 --- a/start.bat +++ b/start.bat @@ -76,4 +76,4 @@ if not "%HOP_HOME%"=="" ( ) :: Invoking the Java virtual machine -%JAVACMD% %JAVA_OPTIONS% -jar "%INSTALL_DIR%\launcher.jar" %OPTIONS% +%JAVACMD% %JAVA_OPTIONS% -jar "%INSTALL_DIR%\launcher.jar" %OPTIONS% %* diff --git a/start.sh b/start.sh index 03ed4550..15df5f00 100755 --- a/start.sh +++ b/start.sh @@ -75,4 +75,4 @@ if [ "$HOP_HOME" ]; then fi # Invoke the Java VM -$JAVACMD $JAVA_OPTIONS -jar "$INSTALL_DIR/launcher.jar" $SWITCHES +$JAVACMD $JAVA_OPTIONS -jar "$INSTALL_DIR/launcher.jar" $SWITCHES $*