diff --git a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/RestartDomainCommand.java b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/RestartDomainCommand.java index f94ffb5e4ee..bf8f36c390b 100644 --- a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/RestartDomainCommand.java +++ b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/RestartDomainCommand.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2018-2021] Payara Foundation and/or affiliates +// Portions Copyright [2018-2023] Payara Foundation and/or affiliates package com.sun.enterprise.admin.servermgmt.cli; @@ -78,6 +78,9 @@ public class RestartDomainCommand extends StopDomainCommand { @Param(name = "debug", optional = true) private Boolean debug; + @Param(optional = true, defaultValue = "600") + protected int timeout; + @Inject private ServiceLocator habitat; private static final LocalStringsImpl STRINGS = new LocalStringsImpl(RestartDomainCommand.class); @@ -98,13 +101,14 @@ protected void doCommand() // run the remote restart-domain command and throw away the output RemoteCLICommand cmd = new RemoteCLICommand("restart-domain", programOpts, env); + cmd.setReadTimeout(timeout * 1000); if (debug != null) cmd.executeAndReturnOutput("restart-domain", "--debug", debug.toString()); else cmd.executeAndReturnOutput("restart-domain"); - waitForRestart(oldServerPid); + waitForRestart(oldServerPid, (timeout * 1000)); logger.info(STRINGS.get("restartDomain.success")); } diff --git a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StartDomainCommand.java b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StartDomainCommand.java index b356931669e..061a894c614 100644 --- a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StartDomainCommand.java +++ b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StartDomainCommand.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -//Portions Copyright [2017-2021] Payara Foundation and/or affiliates +//Portions Copyright [2017-2023] Payara Foundation and/or affiliates package com.sun.enterprise.admin.servermgmt.cli; @@ -64,6 +64,8 @@ import com.sun.enterprise.universal.xml.MiniXmlParserException; import org.glassfish.security.common.FileRealmStorageManager; +import static java.util.concurrent.TimeUnit.SECONDS; + /** * The start-domain command. * @@ -95,6 +97,9 @@ public class StartDomainCommand extends LocalDomainCommand implements StartServe private String preBootCommand; @Param(name = "postbootcommandfile", optional = true) private String postBootCommand; + + @Param(defaultValue = "600", optional = true) + protected int timeout; @Inject ServerEnvironment senv; @@ -132,6 +137,9 @@ protected void validate() throw new CommandValidationException("postboot commands file does not exist: "+ postbootFile.getAbsolutePath()); } } + if (timeout < 1) { + throw new CommandValidationException("Timeout must be at least 1 second long."); + } super.validate(); } @@ -206,7 +214,7 @@ protected int executeCommand() throws CommandException { } else { - helper.waitForServer(); + helper.waitForServer(timeout, SECONDS); helper.report(); return SUCCESS; } diff --git a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StopDomainCommand.java b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StopDomainCommand.java index d3214d5508e..eb899f5e131 100644 --- a/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StopDomainCommand.java +++ b/nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/StopDomainCommand.java @@ -37,11 +37,10 @@ * only if the new code is made subject to such option by the copyright * holder. * - * Portions Copyright [2017-2021] [Payara Foundation and/or its affiliates] + * Portions Copyright [2017-2023] [Payara Foundation and/or its affiliates] */ package com.sun.enterprise.admin.servermgmt.cli; -import com.sun.enterprise.admin.cli.CLIConstants; import com.sun.enterprise.admin.cli.remote.DASUtils; import com.sun.enterprise.admin.cli.remote.RemoteCLICommand; import com.sun.enterprise.universal.process.ProcessUtils; @@ -77,12 +76,19 @@ public class StopDomainCommand extends LocalDomainCommand { Boolean force; @Param(optional = true, defaultValue = "false") Boolean kill; - private static final long WAIT_FOR_DAS_TIME_MS = 60000; // 1 minute + + @Param(optional = true, defaultValue = "60") + protected int timeout; @Override protected void validate() throws CommandException { setDomainName(userArgDomainName); + + if (timeout < 1) { + throw new CommandValidationException("Timeout must be at least 1 second long."); + } + super.validate(); // which calls initDomain() !! } @@ -200,6 +206,7 @@ protected int dasNotRunning() throws CommandException { protected void doCommand() throws CommandException { // run the remote stop-domain command and throw away the output RemoteCLICommand cmd = new RemoteCLICommand(getName(), programOpts, env); + cmd.setReadTimeout(timeout * 1000); try { cmd.executeAndReturnOutput("stop-domain", "--force", force.toString()); } catch (Exception e) { @@ -253,12 +260,12 @@ protected void waitForDeath() throws CommandException { if (alive) { throw new CommandException(Strings.get("StopDomain.DASNotDead", - (WAIT_FOR_DAS_TIME_MS / 1000))); + timeout)); } } private boolean timedOut(long startTime) { - return (System.currentTimeMillis() - startTime) > WAIT_FOR_DAS_TIME_MS; + return (System.currentTimeMillis() - startTime) > (timeout * 1000); } protected int kill() throws CommandException { diff --git a/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/RestartDomainsCommand.java b/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/RestartDomainsCommand.java index 181630195f9..4b4e96e7018 100644 --- a/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/RestartDomainsCommand.java +++ b/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/RestartDomainsCommand.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2017-2018] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2017-2023] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -65,6 +65,9 @@ public class RestartDomainsCommand extends RestartDomainCommand { @Override protected void validate() throws CommandException, CommandValidationException { + if (timeout < 1) { + throw new CommandValidationException("Timeout must be at least 1 second long."); + } } @Override diff --git a/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/StartDomainsCommand.java b/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/StartDomainsCommand.java index c31d8ebddfd..fe8b0a74a37 100644 --- a/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/StartDomainsCommand.java +++ b/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/StartDomainsCommand.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2017] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2017-2023] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -92,6 +92,10 @@ protected void validate() throw new CommandValidationException("postboot commands file does not exist: "+ postbootFile.getAbsolutePath()); } } + + if (timeout < 1) { + throw new CommandValidationException("Timeout must be at least 1 second long."); + } } @Override diff --git a/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/StopAllDomainsCommand.java b/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/StopAllDomainsCommand.java index 0e1756c8f0f..57366af5c26 100644 --- a/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/StopAllDomainsCommand.java +++ b/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/StopAllDomainsCommand.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2017-2018] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2017-2023] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -85,6 +85,9 @@ protected void prevalidate() throws CommandException { protected void validate() throws CommandException, CommandValidationException { // no-op to prevent initDomain being called + if (timeout < 1) { + throw new CommandValidationException("Timeout must be at least 1 second long."); + } } @Override @@ -95,7 +98,11 @@ protected int executeCommand() throws CommandException { String[] domainsList = getDomains(); for (String domain : domainsList) { setConfig(domain); + ParameterMap parameterMap = new ParameterMap(); + parameterMap.insert("timeout", String.valueOf(timeout)); + programOpts.updateOptions(parameterMap); RemoteCLICommand cmd = new RemoteCLICommand("stop-domain", programOpts, env); + cmd.setReadTimeout(timeout * 1000); logger.log(Level.FINE, "Stopping domain {0}", domain); try { cmd.executeAndReturnOutput("stop-domain", "--force", force.toString()); diff --git a/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/StopDomainsCommand.java b/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/StopDomainsCommand.java index bf9c8ca553c..09173eabfe4 100644 --- a/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/StopDomainsCommand.java +++ b/nucleus/admin/server-mgmt/src/main/java/fish/payara/admin/servermgmt/cli/StopDomainsCommand.java @@ -1,8 +1,8 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) [2017-2018] Payara Foundation and/or its affiliates. All rights reserved. - * + * + * Copyright (c) [2017-2023] Payara Foundation and/or its affiliates. All rights reserved. + * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development * and Distribution License("CDDL") (collectively, the "License"). You @@ -46,6 +46,7 @@ import org.glassfish.api.Param; import org.glassfish.api.admin.CommandException; import org.glassfish.api.admin.CommandValidationException; +import org.glassfish.api.admin.ParameterMap; import org.glassfish.hk2.api.MultiException; import org.glassfish.hk2.api.PerLookup; import org.jvnet.hk2.annotations.Service; @@ -71,6 +72,9 @@ public class StopDomainsCommand extends StopDomainCommand { protected void validate() throws CommandException, CommandValidationException { // no-op to prevent initDomain being called + if (timeout < 1) { + throw new CommandValidationException("Timeout must be at least 1 second long."); + } } @Override @@ -81,7 +85,11 @@ protected int executeCommand() throws CommandException { String[] domains = userArgDomainName.split(","); for (String domainName : domains) { setConfig(domainName); + ParameterMap parameterMap = new ParameterMap(); + parameterMap.insert("timeout", String.valueOf(timeout)); + programOpts.updateOptions(parameterMap); RemoteCLICommand cmd = new RemoteCLICommand("stop-domain", programOpts, env); + cmd.setReadTimeout(timeout * 1000); logger.log(Level.FINE, "Stopping domain {0}", domainName); try { cmd.executeAndReturnOutput("stop-domain"); diff --git a/nucleus/admin/server-mgmt/src/main/manpages/com/sun/enterprise/admin/servermgmt/cli/restart-domain.1 b/nucleus/admin/server-mgmt/src/main/manpages/com/sun/enterprise/admin/servermgmt/cli/restart-domain.1 index 3433ac40284..8e07dae425f 100644 --- a/nucleus/admin/server-mgmt/src/main/manpages/com/sun/enterprise/admin/servermgmt/cli/restart-domain.1 +++ b/nucleus/admin/server-mgmt/src/main/manpages/com/sun/enterprise/admin/servermgmt/cli/restart-domain.1 @@ -7,7 +7,7 @@ SYNOPSIS restart-domain [--help] [--debug ={true|false}] [--domaindir domaindir] [--force={true|false}] [--kill={false|true}] - [domain-name] + [--timeout timeout] [domain-name] DESCRIPTION The restart-domain subcommand stops and then restarts the domain @@ -85,6 +85,10 @@ OPTIONS The domain is killed. The subcommand uses functionality of the operating system to terminate the domain process. + --timeout + Specifies the amount of time in seconds the command will run for + before timing out. Default is 600 seconds. + OPERANDS domain-name The name of the domain you want to restart. Default is the name diff --git a/nucleus/admin/server-mgmt/src/main/manpages/com/sun/enterprise/admin/servermgmt/cli/start-domain.1 b/nucleus/admin/server-mgmt/src/main/manpages/com/sun/enterprise/admin/servermgmt/cli/start-domain.1 index ffc8909cfe4..d4b7283dabc 100644 --- a/nucleus/admin/server-mgmt/src/main/manpages/com/sun/enterprise/admin/servermgmt/cli/start-domain.1 +++ b/nucleus/admin/server-mgmt/src/main/manpages/com/sun/enterprise/admin/servermgmt/cli/start-domain.1 @@ -8,7 +8,7 @@ SYNOPSIS [--debug={true|false}] [--domaindir domain-dir] [--dry-run={true|false}] [--upgrade={true|false}] [--verbose={true|false}] [--watchdog={true|false}] - [domain-name] + [--timeout timeout] [domain-name] DESCRIPTION The start-domain subcommand starts the domain administration server @@ -148,6 +148,10 @@ OPTIONS Limited information is not displayed in the console window (default). + --timeout + Specifies the amount of time in seconds the command will run for + before timing out. Default is 600 seconds. + OPERANDS domain-name The unique name of the domain you want to start. diff --git a/nucleus/admin/server-mgmt/src/main/manpages/com/sun/enterprise/admin/servermgmt/cli/stop-domain.1 b/nucleus/admin/server-mgmt/src/main/manpages/com/sun/enterprise/admin/servermgmt/cli/stop-domain.1 index ab742412428..f381f521b64 100644 --- a/nucleus/admin/server-mgmt/src/main/manpages/com/sun/enterprise/admin/servermgmt/cli/stop-domain.1 +++ b/nucleus/admin/server-mgmt/src/main/manpages/com/sun/enterprise/admin/servermgmt/cli/stop-domain.1 @@ -7,7 +7,7 @@ NAME SYNOPSIS stop-domain [--help] [--domaindir domaindir] [--force={true|false}] [--kill={false|true}] - [domain-name] + [--timeout timeout][domain-name] DESCRIPTION The stop-domain subcommand stops the Domain Administration Server (DAS) @@ -61,6 +61,10 @@ OPTIONS The domain is killed. The subcommand uses functionality of the operating system to terminate the domain process. + --timeout + Specifies the amount of time in seconds the command will run for + before timing out. Default is 60 seconds. + OPERANDS domain-name The name of the domain you want to stop. Default is the name