mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +01:00
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:
parent
dbecc0a2f1
commit
1bf1ae4377
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user