mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-26 16:30:50 +01:00
Re-add exit code restart strategy
This commit is contained in:
@@ -25,6 +25,7 @@ package sonia.scm.lifecycle;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.config.WebappConfigProvider;
|
||||
|
||||
/**
|
||||
* {@link RestartStrategy} which tears down the scm-manager context and
|
||||
@@ -49,7 +50,8 @@ class ExitRestartStrategy extends RestartStrategy {
|
||||
|
||||
@Override
|
||||
protected void executeRestart(InjectionContext context) {
|
||||
LOG.warn("exit scm-manager with exit code {}", 0);
|
||||
System.exit(0);
|
||||
Integer exitCode = WebappConfigProvider.resolveAsInteger("restart.exitCode").orElse(0);
|
||||
LOG.warn("exit scm-manager with exit code {}", exitCode);
|
||||
System.exit(exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,18 +26,18 @@ package sonia.scm.lifecycle;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Strings;
|
||||
import sonia.scm.Platform;
|
||||
import sonia.scm.config.WebappConfigProvider;
|
||||
import sonia.scm.util.SystemUtil;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
final class RestartStrategyFactory {
|
||||
|
||||
/**
|
||||
* System property to load a specific restart strategy.
|
||||
*/
|
||||
static final String PROPERTY_STRATEGY = "sonia.scm.lifecycle.restart-strategy";
|
||||
static final String RESTART_STRATEGY = "restart.strategy";
|
||||
|
||||
/**
|
||||
* No restart supported.
|
||||
@@ -46,13 +46,11 @@ final class RestartStrategyFactory {
|
||||
|
||||
private final Platform platform;
|
||||
private final Map<String, String> environment;
|
||||
private final Properties systemProperties;
|
||||
|
||||
@VisibleForTesting
|
||||
RestartStrategyFactory(Platform platform, Map<String, String> environment, Properties systemProperties) {
|
||||
RestartStrategyFactory(Platform platform, Map<String, String> environment) {
|
||||
this.platform = platform;
|
||||
this.environment = environment;
|
||||
this.systemProperties = systemProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,28 +62,27 @@ final class RestartStrategyFactory {
|
||||
static RestartStrategy create(ClassLoader webAppClassLoader) {
|
||||
RestartStrategyFactory factory = new RestartStrategyFactory(
|
||||
SystemUtil.getPlatform(),
|
||||
System.getenv(),
|
||||
System.getProperties()
|
||||
System.getenv()
|
||||
);
|
||||
return factory.fromClassLoader(webAppClassLoader);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
RestartStrategy fromClassLoader(ClassLoader webAppClassLoader) {
|
||||
String property = systemProperties.getProperty(PROPERTY_STRATEGY);
|
||||
if (Strings.isNullOrEmpty(property)) {
|
||||
String strategy = WebappConfigProvider.resolveAsString(RESTART_STRATEGY).orElse(null);
|
||||
if (Strings.isNullOrEmpty(strategy)) {
|
||||
return forPlatform();
|
||||
}
|
||||
return fromProperty(webAppClassLoader, property);
|
||||
return forStrategy(webAppClassLoader, strategy);
|
||||
}
|
||||
|
||||
private RestartStrategy fromProperty(ClassLoader webAppClassLoader, String property) {
|
||||
if (STRATEGY_NONE.equalsIgnoreCase(property)) {
|
||||
private RestartStrategy forStrategy(ClassLoader webAppClassLoader, String strategy) {
|
||||
if (STRATEGY_NONE.equalsIgnoreCase(strategy)) {
|
||||
return null;
|
||||
} else if (ExitRestartStrategy.NAME.equalsIgnoreCase(property)) {
|
||||
} else if (ExitRestartStrategy.NAME.equalsIgnoreCase(strategy)) {
|
||||
return new ExitRestartStrategy();
|
||||
} else {
|
||||
return fromClassName(property, webAppClassLoader);
|
||||
return fromClassName(strategy, webAppClassLoader);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user