diff --git a/modules/launcher/launcher-impl/src/main/java/com/enonic/xp/launcher/impl/framework/FrameworkService.java b/modules/launcher/launcher-impl/src/main/java/com/enonic/xp/launcher/impl/framework/FrameworkService.java index 6b98f9bed79..9b0440d3e74 100644 --- a/modules/launcher/launcher-impl/src/main/java/com/enonic/xp/launcher/impl/framework/FrameworkService.java +++ b/modules/launcher/launcher-impl/src/main/java/com/enonic/xp/launcher/impl/framework/FrameworkService.java @@ -14,6 +14,7 @@ import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; +import org.osgi.framework.FrameworkEvent; import org.osgi.framework.ServiceReference; import org.osgi.framework.hooks.weaving.WeavingHook; import org.osgi.framework.startlevel.BundleStartLevel; @@ -31,7 +32,7 @@ public class FrameworkService { private static final Logger LOG = LoggerFactory.getLogger( FrameworkService.class ); - public static final int WAIT_FOR_STOP_TIMEOUT_MS = 10_000; + private static final int WAIT_FOR_STOP_TIMEOUT_MS = 600_000; private final ConfigProperties config; @@ -39,6 +40,8 @@ public class FrameworkService private final Map services = new ConcurrentHashMap<>(); + private final long stopGracePeriod; + private volatile Felix felix; private volatile long startTime; @@ -46,6 +49,7 @@ public class FrameworkService public FrameworkService( final ConfigProperties config ) { this.config = config; + this.stopGracePeriod = Long.getLong( "xp.stop.gracePeriod", WAIT_FOR_STOP_TIMEOUT_MS ); } public FrameworkService activator( final BundleActivator activator ) @@ -151,7 +155,15 @@ public void stop() public void restart() { LOG.info( "Restarting server..." ); - stop(); + try + { + doStop(); + } + catch ( Exception e ) + { + LOG.error( "Restarting failed. Try restarting manually.", e ); + return; + } start(); } @@ -181,7 +193,12 @@ private void doStop() { stopActivators(); this.felix.stop(); - this.felix.waitForStop( WAIT_FOR_STOP_TIMEOUT_MS ); + + final FrameworkEvent frameworkEvent = this.felix.waitForStop( stopGracePeriod ); + if ( frameworkEvent.getType() != FrameworkEvent.STOPPED ) + { + throw new IllegalStateException( "Failed to stop framework: " + frameworkEvent.getType(), frameworkEvent.getThrowable() ); + } } private void startActivators() diff --git a/modules/launcher/launcher-impl/src/main/resources/META-INF/config/system.properties b/modules/launcher/launcher-impl/src/main/resources/META-INF/config/system.properties index d3e3a2f7773..3f3632f0adf 100644 --- a/modules/launcher/launcher-impl/src/main/resources/META-INF/config/system.properties +++ b/modules/launcher/launcher-impl/src/main/resources/META-INF/config/system.properties @@ -68,4 +68,5 @@ xp.config.paths=${xp.home}/config # Initialization settings # # xp.init.maxTries = 300 +# xp.stop.gracePeriod = 600000 diff --git a/modules/runtime/src/home/config/system.properties b/modules/runtime/src/home/config/system.properties index 433a2d87a9a..34e8424c42c 100644 --- a/modules/runtime/src/home/config/system.properties +++ b/modules/runtime/src/home/config/system.properties @@ -12,6 +12,7 @@ # # xp.init.adminUserCreation = true # xp.init.maxTries = 300 +# xp.stop.gracePeriod = 600000 # # Configuration FileMonitor properties