Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
Fix shutdown when hitting Ctrl+C
Browse files Browse the repository at this point in the history
Fixes #237
  • Loading branch information
GiantTreeLP committed Mar 3, 2020
1 parent 40a606d commit ae3d005
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ public void shutdownAll() {
}
try {
this.reader.killLine();
this.reader.close();
this.reader.flush();
System.out.flush();
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ public static CloudNetWrapper getInstance() {
@Override
public boolean bootstrap() throws Exception {

Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHook(this)));
final Thread hook = new Thread(new ShutdownHook(this));
hook.setDaemon(true);
Runtime.getRuntime().addShutdownHook(hook);
if (!optionSet.has("disable-autoupdate")) {
checkForUpdates();
}
Expand Down Expand Up @@ -263,18 +265,18 @@ public boolean shutdown() {
return false;
} else {
RUNNING = false;

}
System.out.println("Wrapper shutdown...");

getExecutor().shutdownNow();

if (SpigotBuilder.getExec() != null) {
SpigotBuilder.getExec().destroyForcibly();
}
if (PaperBuilder.getExec() != null) {
PaperBuilder.getExec().destroyForcibly();
}

getExecutor().shutdownNow();

if (serverProcessQueue != null) {
serverProcessQueue.setRunning(false);
serverProcessQueue.getProxies().clear();
Expand All @@ -295,23 +297,19 @@ public boolean shutdown() {

FileUtility.deleteDirectory(new File("temp"));

System.out.println();

System.out.println(" _ _ _______ _ _ ");
System.out.println(" _| || |_ |__ __| | | | | ");
System.out.println(" |_ __ _| | | | |__ __ _ _ __ | | __ ___ ");
System.out.println(" _| || |_ | | | '_ \\ / _` | | '_ \\ | |/ / / __|");
System.out.println(" |_ __ _| | | | | | | | (_| | | | | | | < \\__ \\");
System.out.println(" |_||_| |_| |_| |_| \\__,_| |_| |_| |_|\\_\\ |___/");
System.out.println();
this.cloudNetLogging.info(" _ _ _______ _ _ ");
this.cloudNetLogging.info(" _| || |_ |__ __| | | | | ");
this.cloudNetLogging.info(" |_ __ _| | | | |__ __ _ _ __ | | __ ___ ");
this.cloudNetLogging.info(" _| || |_ | | | '_ \\ / _` | | '_ \\ | |/ / / __|");
this.cloudNetLogging.info(" |_ __ _| | | | | | | | (_| | | | | | | < \\__ \\");
this.cloudNetLogging.info(" |_||_| |_| |_| |_| \\__,_| |_| |_| |_|\\_\\ |___/");

this.cloudNetLogging.shutdownAll();
try {
getExecutor().awaitTermination(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.exit(0);
this.cloudNetLogging.shutdownAll();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static void main(String[] args) throws Exception {
}
}
} else {
while (!Thread.currentThread().isInterrupted()) {
while (!Thread.currentThread().isInterrupted() && CloudNetWrapper.RUNNING) {
NetworkUtils.sleepUninterruptedly(Long.MAX_VALUE);
}
}
Expand Down

0 comments on commit ae3d005

Please sign in to comment.