Added graceful shutdown hook

Graceful shutdown has only be done in case of an error or when
using the GUI. A regular eg. seednode shutdown is not covered
though.

Now, SIGTERM and SIGINT triggers a graceful shutdown procedure.
This commit is contained in:
Florian Reimair 2020-03-11 13:49:44 +01:00
parent dbecc0a2f1
commit 1bf1ae4377
No known key found for this signature in database
GPG Key ID: 05634D8D7A7954C8

View File

@ -49,6 +49,10 @@ import java.io.File;
import lombok.extern.slf4j.Slf4j;
import sun.misc.Signal;
@Slf4j
public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSetup.BisqSetupListener {
@ -63,6 +67,7 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
protected Injector injector;
protected AppModule module;
protected Config config;
private boolean isShutdown = false;
public BisqExecutable(String fullName, String scriptName, String appName, String version) {
this.fullName = fullName;
@ -100,6 +105,16 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
CoreSetup.setup(config);
addCapabilities();
Signal.handle(new Signal("INT"), signal -> {
gracefulShutDown(() -> {
});
});
Signal.handle(new Signal("TERM"), signal -> {
gracefulShutDown(() -> {
});
});
// If application is JavaFX application we need to wait until it is initialized
launchApplication();
}
@ -189,6 +204,10 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
// This might need to be overwritten in case the application is not using all modules
@Override
public void gracefulShutDown(ResultHandler resultHandler) {
if (isShutdown) // prevent double cleanup
return;
isShutdown = true;
try {
if (injector != null) {
injector.getInstance(ArbitratorManager.class).shutDown();