From e17887d36c902474413e3fbcce33b8c819982375 Mon Sep 17 00:00:00 2001 From: e001946 Date: Tue, 29 Aug 2017 11:49:48 +0200 Subject: [PATCH 1/4] Adds the "startWinService" mode for a server command --- docs/server.md | 3 ++- .../java/net/wasdev/wlp/ant/ServerTask.java | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/server.md b/docs/server.md index 7f58b1b1..45b80a1b 100644 --- a/docs/server.md +++ b/docs/server.md @@ -5,6 +5,7 @@ The `server` task supports the following operations: * `create` - creates a named server instance. * `start` - starts the named server instance in background. If the server instance does not exist, this option creates one by default. +* `startWinService` - starts the named server Windows service. * `run` - start the named service instance in foreground. If the server instance does not exist, this option creates one by default. * `stop` - stops the named server. * `status` - checks the server status. @@ -18,7 +19,7 @@ Parameters supported by this task in addition to the [common parameters](common- | Attribute | Description | Required | | --------- | ------------ | ----------| -| operation | Server operations available as options: `create`, `start`, `run`, `stop`, `status`, `package`, `dump`, and `javadump`. | Yes | +| operation | Server operations available as options: `create`, `start`, `startWinService`, `run`, `stop`, `status`, `package`, `dump`, and `javadump`. | Yes | | clean | Clean all cached information on server start up. The default value is `false`. Only used with the `start` operation. | No | | timeout | Waiting time before the server starts. The default value is 30 seconds. The unit is milliseconds. Only used with the `start` operation. | No | | include | A comma-delimited list of values. The valid values vary depending on the operation. For the `package` operation the valid values are `all`, `usr`, and `minify`. For the `dump` operation the valid values are `heap`, `system`, and `thread`. For the `javadump` operation the valid values are `heap` and `system`. | Yes, only when the `os` option is set | diff --git a/src/main/java/net/wasdev/wlp/ant/ServerTask.java b/src/main/java/net/wasdev/wlp/ant/ServerTask.java index 7b7452d9..62f6e46e 100644 --- a/src/main/java/net/wasdev/wlp/ant/ServerTask.java +++ b/src/main/java/net/wasdev/wlp/ant/ServerTask.java @@ -98,6 +98,8 @@ public void execute() { doRun(); } else if ("start".equals(operation)) { doStart(); + } else if ("startWinService".equals(operation)) { + doStartWinService(); } else if ("stop".equals(operation)) { doStop(); } else if ("status".equals(operation)) { @@ -141,6 +143,21 @@ private void doStart() throws Exception { } validateServerStarted(getLogFile(), startTimeout); } + + private void doStartWinService() throws Exception { + List command = getInitialCommand(operation); + addCleanOption(command); + processBuilder.command(command); + Process p = processBuilder.start(); + checkReturnCode(p, processBuilder.command().toString(), ReturnCode.OK.getValue(), ReturnCode.REDUNDANT_ACTION_STATUS.getValue()); + + // check server started message code. + long startTimeout = SERVER_START_TIMEOUT_DEFAULT; + if (timeout != null && !timeout.equals("")) { + startTimeout = Long.valueOf(timeout); + } + validateServerStarted(getLogFile(), startTimeout); + } private void validateServerStarted(File outputFile, long startTimeout) throws Exception { From 4139f46b6cd05e3596925484a8410f28250e200f Mon Sep 17 00:00:00 2001 From: e001946 Date: Thu, 7 Sep 2017 17:53:57 +0200 Subject: [PATCH 2/4] Implements ServerLogDir attribute --- .../java/net/wasdev/wlp/ant/AbstractTask.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/wasdev/wlp/ant/AbstractTask.java b/src/main/java/net/wasdev/wlp/ant/AbstractTask.java index 402e272d..dd524706 100644 --- a/src/main/java/net/wasdev/wlp/ant/AbstractTask.java +++ b/src/main/java/net/wasdev/wlp/ant/AbstractTask.java @@ -39,19 +39,20 @@ public abstract class AbstractTask extends Task { protected File installDir; protected File userDir; protected File outputDir; - protected File serverConfigDir = null; - protected File serverOutputDir = null; + protected File serverLogDir; protected String serverName; - protected String ref; + protected File serverConfigDir = null; + protected File serverOutputDir = null; + protected static String osName; protected static boolean isWindows; protected ProcessBuilder processBuilder; protected static final String DEFAULT_SERVER = "defaultServer"; - protected static final String DEFAULT_LOG_FILE = "logs/messages.log"; + protected static final String DEFAULT_LOG_FILE = "messages.log"; protected static final String WLP_USER_DIR_VAR = "WLP_USER_DIR"; protected static final String WLP_OUTPUT_DIR_VAR = "WLP_OUTPUT_DIR"; @@ -66,6 +67,7 @@ protected void initTask() { setServerName(((ServerTask) serverRef).getServerName()); setUserDir(((ServerTask) serverRef).getUserDir()); setOutputDir(((ServerTask) serverRef).getOutputDir()); + setServerLogDir(((ServerTask) serverRef).getServerLogDir()); } } @@ -122,6 +124,12 @@ protected void initTask() { } log(MessageFormat.format(messages.getString("info.variable"), "server.output.dir", serverOutputDir.getCanonicalPath())); + + if (serverLogDir == null) { + serverLogDir = new File(serverOutputDir, "logs"); + } + + log(MessageFormat.format(messages.getString("info.variable"), "server.log.dir", serverLogDir.getCanonicalPath())); } catch (IOException e) { throw new BuildException(e); } @@ -156,6 +164,14 @@ public void setOutputDir(File outputDir) { this.outputDir = outputDir; } + public File getServerLogDir() { + return serverLogDir; + } + + public void setServerLogDir(File serverLogDir) { + this.serverLogDir = serverLogDir; + } + /** * @return the serverName */ @@ -172,7 +188,7 @@ public void setServerName(String serverName) { } public File getLogFile() { - return new File(serverOutputDir, DEFAULT_LOG_FILE); + return new File(serverLogDir, DEFAULT_LOG_FILE); } /** From 9a2038a97520b2760dd162c005169b0a829abcc7 Mon Sep 17 00:00:00 2001 From: e001946 Date: Thu, 7 Sep 2017 17:59:43 +0200 Subject: [PATCH 3/4] Update the server doc for serverLogDir attribute --- docs/server.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/server.md b/docs/server.md index 45b80a1b..04e00bdd 100644 --- a/docs/server.md +++ b/docs/server.md @@ -27,6 +27,7 @@ Parameters supported by this task in addition to the [common parameters](common- | archive | Location of the target archive file. Only used with the `package` or `dump` operations. | No | | template | Name of the template to use when creating a new server. Only used with the `create` operation. | No | | resultProperty | Name of a property in which the server status will be stored. By default the server status will be stored under `wlp..status` property. Only used with the `status` operation. | No | +| serverLogDir | Location of the server log where the message.log file can be found. | No | #### Examples From 54df95e364c7b1b7b7f1e3cb14810e4c32dd59f5 Mon Sep 17 00:00:00 2001 From: e001946 Date: Thu, 7 Sep 2017 18:30:23 +0200 Subject: [PATCH 4/4] Release 1.3-AM_Patch1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e3002a0d..e2d58321 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ net.wasdev.wlp.ant wlp-anttasks - 1.4-SNAPSHOT + 1.3-AM_Patch1 WebSphere Application Server Liberty Profile Ant Tasks Parent pom for Ant tasks supporting development with