From b020029802293c59e2423432cedf1f071c18c849 Mon Sep 17 00:00:00 2001 From: Lucas Saldanha Date: Mon, 12 Nov 2018 11:41:56 +1300 Subject: [PATCH] Add shutdown hook to PantheonCommand (#249) --- .../tech/pegasys/pantheon/cli/PantheonCommand.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index 101e0795c3..a8793a891f 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -493,9 +493,23 @@ public class PantheonCommand implements Runnable { webSocketConfiguration, dataDir); + addShutdownHook(runner); runner.execute(); } + private void addShutdownHook(final Runner runner) { + Runtime.getRuntime() + .addShutdownHook( + new Thread( + () -> { + try { + runner.close(); + } catch (Exception e) { + throw new RuntimeException(e); + } + })); + } + // Used to discover the default IP of the client. // Loopback IP is used by default as this is how smokeTests require it to be // and it's probably a good security behaviour to default only on the localhost.