More robust shutdown on startup failure
diff --git a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java
index ff97d81..ab6f6ac 100644
--- a/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java
+++ b/nucleus/core/bootstrap/src/main/java/com/sun/enterprise/glassfish/bootstrap/GlassFishMain.java
@@ -101,9 +101,11 @@
try {
System.out.println("command = " + command);
if ("start".equalsIgnoreCase(command)) {
- if (gf.getStatus() != GlassFish.Status.STARTED || gf.getStatus() == GlassFish.Status.STOPPING || gf.getStatus() == GlassFish.Status.STARTING)
+ if (gf.getStatus() != GlassFish.Status.STARTED || gf.getStatus() == GlassFish.Status.STOPPING || gf.getStatus() == GlassFish.Status.STARTING) {
gf.start();
- else System.out.println("Already started or stopping or starting");
+ } else {
+ System.out.println("Already started or stopping or starting");
+ }
} else if ("stop".equalsIgnoreCase(command)) {
if (gf.getStatus() != GlassFish.Status.STARTED) {
System.out.println("GlassFish is not started yet. Please execute start first.");
@@ -174,9 +176,12 @@
private void addShutdownHook() {
Runtime.getRuntime().addShutdownHook(new Thread("GlassFish Shutdown Hook") {
+ @Override
public void run() {
try {
- gfr.shutdown();
+ if (gfr != null) {
+ gfr.shutdown();
+ }
}
catch (Exception ex) {
System.err.println("Error stopping framework: " + ex);