Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

Restart feature #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/org/jboss/as/plugin/common/PropertyNames.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public interface PropertyNames {

String RELOAD_TIMEOUT = "jboss-as.reload.timeout";

String RESTART = "jboss-as.restart";

String RESTART_TIMEOUT = "jboss-as.restart.timeout";

String SERVER_CONFIG = "jboss-as.serverConfig";

String SKIP = "jboss-as.skip";
Expand Down
42 changes: 33 additions & 9 deletions src/main/java/org/jboss/as/plugin/server/Shutdown.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/**
* Shuts down a running JBoss Application Server.
* <p/>
* Can also be used to issue a reload instead of a full shutdown.
* Can also be used to issue a reload or a restart instead of a full shutdown.
*
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
Expand All @@ -60,27 +60,40 @@ public class Shutdown extends AbstractServerMojo {
@Parameter(defaultValue = "30", property = PropertyNames.RELOAD_TIMEOUT, alias = "reload-timeout")
private int reloadTimeout;

/**
* Set to {@code true} if a {@code restart} operation should be invoked instead of a {@code shutdown}.
*/
@Parameter(defaultValue = "false", property = PropertyNames.RESTART)
private boolean restart;

/**
* The maximum time, in seconds, to wait for a live server after a restart.
*/
@Parameter(defaultValue = "30", property = PropertyNames.RESTART_TIMEOUT, alias = "restart-timeout")
private int restartTimeout;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (isSkip()) {
getLog().debug("Skipping server start");
getLog().debug("Skipping server shutdown");
return;
}
try {
final ModelControllerClient client = getClient();
if (reload) {
client.execute(ServerOperations.createOperation(ServerOperations.RELOAD));
waitForStandalone(client, reloadTimeout);
} else if (restart) {
getLog().debug("Restarting");
ModelNode modelNode = ServerOperations.createOperation(ServerOperations.SHUTDOWN);
modelNode.get("restart").set(true);
client.execute(modelNode);
waitForStandalone(client, restartTimeout);
getLog().debug("We are back!");
} else {
client.execute(ServerOperations.createOperation(ServerOperations.SHUTDOWN));
}
// Bad hack to get maven to complete it's message output
try {
TimeUnit.MILLISECONDS.sleep(500L);
} catch (InterruptedException ignore) {
ignore.printStackTrace();
// no-op
}
waitForMessageOutput();
} catch (Exception e) {
throw new MojoExecutionException(String.format("Could not execute goal %s. Reason: %s", goal(), e.getMessage()), e);
} finally {
Expand All @@ -93,6 +106,17 @@ public String goal() {
return "shutdown";
}


private void waitForMessageOutput() {
// Bad hack to get maven to complete it's message output
try {
TimeUnit.MILLISECONDS.sleep(500L);
} catch (InterruptedException ignore) {
// ignore.printStackTrace();
// no-op
}
}

private void waitForStandalone(final ModelControllerClient client, final int startupTimeout) throws InterruptedException, IOException {
long timeout = startupTimeout * 1000;
final long sleep = 100L;
Expand Down