Permalink
Browse files

AS7-6037 HostController should abort on determineEnvironment issues

Use ExitCode constants for normal and standard failed exits
  • Loading branch information...
1 parent 259e503 commit b78b73d6c2828deb24635e0cf90ca509b54f8122 @bstansberry bstansberry committed Dec 20, 2012
@@ -81,7 +81,7 @@ public static void main(String[] args) throws IOException {
StreamUtils.readFully(System.in, authKey);
} catch (IOException e) {
System.err.println(MESSAGES.failedToReadAuthenticationKey(e));
- System.exit(1);
+ fail();
return;
}
@@ -118,7 +118,7 @@ private HostControllerBootstrap boot(String[] args, final byte[] authCode) {
try {
final HostControllerEnvironment config = determineEnvironment(args);
if (config == null) {
- restart();
+ abort();
return null;
} else {
try {
@@ -137,8 +137,9 @@ private HostControllerBootstrap boot(String[] args, final byte[] authCode) {
}
/**
- * Terminates process controller. JVM shuts down with {@link ExitCodes.HOST_CONTROLLER_ABORT_EXIT_CODE}.
- * @param t
+ * Terminates process with an exit code that will trigger shutdown of the process controller as well if there
+ * are no running servers. JVM shuts down with {@link ExitCodes#HOST_CONTROLLER_ABORT_EXIT_CODE}.
+ * @param t the throwable that triggered abort
*/
private static void abort(Throwable t) {
try {
@@ -153,18 +154,19 @@ private static void abort(Throwable t) {
private static void abort() {
SystemExiter.exit(ExitCodes.HOST_CONTROLLER_ABORT_EXIT_CODE);
}
+
/**
- * Shits down JVM with exit code which triggers restart of controller.
+ * Terminates JVM with exit code: 0 - normal termination.
*/
- private static void restart(){
- SystemExiter.exit(ExitCodes.RESTART_PROCESS_FROM_STARTUP_SCRIPT);
+ private static void exit(){
+ SystemExiter.exit(ExitCodes.NORMAL);
}
/**
- * Terminates JVM with exit code: 0 - normal termination.
+ * Terminates JVM with exit code: 1 - failed termination but not an abort situation.
*/
- private static void exit(){
- SystemExiter.exit(0);
+ private static void fail(){
+ SystemExiter.exit(ExitCodes.FAILED);
}
/**
@@ -380,7 +382,7 @@ private static HostControllerEnvironment determineEnvironment(String[] args) {
if (value == null) {
return null;
}
- String propertyName = null;
+ String propertyName;
if (idx < 0) {
// -b xxx -bmanagement xxx
propertyName = arg.length() == 2 ? HostControllerEnvironment.JBOSS_BIND_ADDRESS : HostControllerEnvironment.JBOSS_BIND_ADDRESS_PREFIX + arg.substring(2);
@@ -27,7 +27,21 @@
* @author <a href="kabir.khan@jboss.com">Kabir Khan</a>
*/
public class ExitCodes {
- /** Exit code which serves two functions:
+
+ /**
+ * Exit code which indicates normal process exit.
+ */
+ public static final int NORMAL = 0;
+
+ /**
+ * Exit code which indicates a process failure. In a managed domain, if the process emitting this code is
+ * a {@code HostController}, the process controller will react to this code by attempting to respawn the host
+ * controller. For other processes this code has no special semantic associated with it.
+ */
+ public static final int FAILED = 1;
+
+ /**
+ * Exit code which serves two functions:
* <ul>
* <li>
* <b>standalone mode:</b> - if a standalone server's exit code the startup script will start up the server again.
@@ -41,6 +55,14 @@
*/
public static final int RESTART_PROCESS_FROM_STARTUP_SCRIPT = 10;
- /** Exit code from host controller which the process controller does not try to respawn, and leads to the process controller shutting down in turn*/
+ /**
+ * Exit code from host controller which indicates a critical boot failure. The process controller
+ * will only try to respawn the host controller if there are no running servers; if there aren't,
+ * the process controller will shut down in turn. If there are running servers, the process controller
+ * will attempt to respawn the host controller, but with longer delays between respawn attempts
+ * than would be the case with {@link #FAILED}. The expectation is a critical boot failure will require
+ * some sort of human intervention to resolve, so immediately respawning will just result in
+ * noise in the logs.
+ */
public static final int HOST_CONTROLLER_ABORT_EXIT_CODE = 99;
}
@@ -333,7 +333,7 @@ public void run() {
new Thread(new Runnable() {
public void run() {
processController.shutdown();
- System.exit(0);
+ System.exit(ExitCodes.NORMAL);
}
}).start();
}
@@ -29,6 +29,7 @@
import java.io.PrintStream;
import java.util.Arrays;
+import org.jboss.as.process.ExitCodes;
import org.jboss.as.process.protocol.StreamUtils;
import org.jboss.as.server.mgmt.domain.HostControllerClient;
import org.jboss.as.server.mgmt.domain.HostControllerConnectionService;
@@ -93,7 +94,7 @@ public static void main(String[] args) {
org.jboss.as.process.protocol.StreamUtils.readFully(initialInput, authKey);
} catch (IOException e) {
e.printStackTrace();
- System.exit(1);
+ System.exit(ExitCodes.FAILED);
throw new IllegalStateException(); // not reached
}
@@ -119,7 +120,7 @@ public void activate(final ServiceActivatorContext serviceActivatorContext) {
}));
} catch (Exception e) {
e.printStackTrace(initialError);
- System.exit(1);
+ System.exit(ExitCodes.FAILED);
throw new IllegalStateException(); // not reached
} finally {
}
@@ -148,7 +149,7 @@ public void activate(final ServiceActivatorContext serviceActivatorContext) {
}
// Once the input stream is cut off, shut down
- System.exit(0);
+ System.exit(ExitCodes.NORMAL);
throw new IllegalStateException(); // not reached
}
@@ -33,6 +33,7 @@
import org.jboss.as.controller.RunningMode;
import org.jboss.as.process.CommandLineConstants;
+import org.jboss.as.process.ExitCodes;
import org.jboss.as.version.ProductConfig;
import org.jboss.logmanager.Level;
import org.jboss.logmanager.Logger;
@@ -106,7 +107,7 @@ private static void abort(Throwable t) {
t.printStackTrace(System.err);
}
} finally {
- SystemExiter.exit(1);
+ SystemExiter.exit(ExitCodes.FAILED);
}
}
@@ -70,7 +70,7 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
processState.setStopping();
final Thread thread = new Thread(new Runnable() {
public void run() {
- System.exit(restart ? ExitCodes.RESTART_PROCESS_FROM_STARTUP_SCRIPT : 0);
+ System.exit(restart ? ExitCodes.RESTART_PROCESS_FROM_STARTUP_SCRIPT : ExitCodes.NORMAL);
}
});
// The intention is that this shutdown is graceful, and so the client gets a reply.

0 comments on commit b78b73d

Please sign in to comment.