From 1bf1ae43777d44c82566693aea7c49d7f7f0ae96 Mon Sep 17 00:00:00 2001 From: Florian Reimair Date: Wed, 11 Mar 2020 13:49:44 +0100 Subject: [PATCH] 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. --- .../java/bisq/core/app/BisqExecutable.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index 39a9461b51..d336550260 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -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();