Repository: quarkusio/quarkus
Issue: Command line app ignores SIGINT (Ctrl+C)

**Describe the bug**
Quarkus command line apps do not respond to SIGINT

**Expected behavior**
A Quarkus command line app should initiate shutdown when passed SIGINT (Ctrl+C on a terminal)

**Actual behavior**
The signal is ignored, nothing happens

**To Reproduce**
Steps to reproduce the behavior:
1. Clone https://github.com/ivangreene/my-quarkus-cli
2. Run `mvn clean package`
3. Run `java -jar target/my-quarkus-cli-1.0-SNAPSHOT-runner.jar`
4. Press Ctrl+C

**Environment (please complete the following information):**
 - Output of `uname -a` or `ver`: `Darwin ivan.local 19.6.0 Darwin Kernel Version 19.6.0: Sun Jul  5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64 x86_64 i386 MacBookPro16,1 Darwin`
 - Output of `java -version`:
```
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.7+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)
```
 - GraalVM version (if different from Java): 
 - Quarkus version or git rev: `1.7.1.Final`
 - Build tool (ie. output of `mvnw --version` or `gradlew --version`):
```
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 11.0.7, vendor: AdoptOpenJDK, runtime: /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.6", arch: "x86_64", family: "mac"
```

Changed files:
core/runtime/src/main/java/io/quarkus/runtime/Application.java, core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java, core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java

diff --git a/core/runtime/src/main/java/io/quarkus/runtime/Application.java b/core/runtime/src/main/java/io/quarkus/runtime/Application.java
index 709b391261e..ac632628c96 100644
--- a/core/runtime/src/main/java/io/quarkus/runtime/Application.java
+++ b/core/runtime/src/main/java/io/quarkus/runtime/Application.java
@@ -228,16 +228,15 @@ public void awaitShutdown() {
         stateLock.lock();
         try {
             for (;;) {
-                switch (state) {
-                    case ST_STOPPED:
-                        return; // all good
-                    default:
-                        try {
-                            stateCond.await();
-                        } catch (InterruptedException e) {
-                            Thread.currentThread().interrupt();
-                            throw interruptedOnAwaitStop();
-                        }
+                if (state == ST_STOPPED) {
+                    return; // all good
+                } else {
+                    try {
+                        stateCond.await();
+                    } catch (InterruptedException e) {
+                        Thread.currentThread().interrupt();
+                        throw interruptedOnAwaitStop();
+                    }
                 }
             }
         } finally {
diff --git a/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java b/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java
index 911e549850e..f12a92b8c07 100644
--- a/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java
+++ b/core/runtime/src/main/java/io/quarkus/runtime/ApplicationLifecycleManager.java
@@ -1,5 +1,6 @@
 package io.quarkus.runtime;
 
+import java.util.Locale;
 import java.util.Objects;
 import java.util.Set;
 import java.util.concurrent.locks.Condition;
@@ -16,8 +17,6 @@
 import org.jboss.logging.Logger;
 import org.wildfly.common.lock.Locks;
 
-import com.oracle.svm.core.OS;
-
 import io.quarkus.runtime.graal.DiagnosticPrinter;
 import sun.misc.Signal;
 import sun.misc.SignalHandler;
@@ -74,7 +73,7 @@ public static void run(Application application, Class<? extends QuarkusApplicati
         //in this case we don't shut it down at the end
         boolean alreadyStarted = application.isStarted();
         if (!hooksRegistered) {
-            registerHooks();
+            registerHooks(exitCodeHandler == null ? defaultExitCodeHandler : exitCodeHandler);
             hooksRegistered = true;
         }
         if (currentApplication != null && !shutdownRequested) {
@@ -104,7 +103,7 @@ public static void run(Application application, Class<? extends QuarkusApplicati
                 }
                 QuarkusApplication instance;
                 if (bean == null) {
-                    instance = quarkusApplication.newInstance();
+                    instance = quarkusApplication.getDeclaredConstructor().newInstance();
                 } else {
                     CreationalContext<?> ctx = beanManager.createCreationalContext(bean);
                     instance = (QuarkusApplication) beanManager.getReference(bean, quarkusApplication, ctx);
@@ -159,36 +158,36 @@ public static void run(Application application, Class<? extends QuarkusApplicati
         (exitCodeHandler == null ? defaultExitCodeHandler : exitCodeHandler).accept(getExitCode()); //this may not be called if shutdown was initiated by a signal
     }
 
-    private static void registerHooks() {
+    private static void registerHooks(final Consumer<Integer> exitCodeHandler) {
         if (ImageInfo.inImageRuntimeCode() && System.getenv(DISABLE_SIGNAL_HANDLERS) == null) {
-            registerSignalHandlers();
+            registerSignalHandlers(exitCodeHandler);
         }
         final ShutdownHookThread shutdownHookThread = new ShutdownHookThread();
         Runtime.getRuntime().addShutdownHook(shutdownHookThread);
     }
 
-    private static void registerSignalHandlers() {
-        final SignalHandler handler = new SignalHandler() {
+    private static void registerSignalHandlers(final Consumer<Integer> exitCodeHandler) {
+        final SignalHandler exitHandler = new SignalHandler() {
             @Override
             public void handle(Signal signal) {
-                System.exit(signal.getNumber() + 0x80);
+                exitCodeHandler.accept(signal.getNumber() + 0x80);
             }
         };
-        final SignalHandler quitHandler = new SignalHandler() {
+        final SignalHandler diagnosticsHandler = new SignalHandler() {
             @Override
             public void handle(Signal signal) {
                 DiagnosticPrinter.printDiagnostics(System.out);
             }
         };
-        handleSignal("INT", handler);
-        handleSignal("TERM", handler);
+        handleSignal("INT", exitHandler);
+        handleSignal("TERM", exitHandler);
         // the HUP and QUIT signals are not defined for the Windows OpenJDK implementation:
         // https://hg.openjdk.java.net/jdk8u/jdk8u-dev/hotspot/file/7d5c800dae75/src/os/windows/vm/jvm_windows.cpp
-        if (OS.getCurrent() == OS.WINDOWS) {
-            handleSignal("BREAK", quitHandler);
+        if (System.getProperty("os.name", "unknown").toLowerCase(Locale.ENGLISH).contains("windows")) {
+            handleSignal("BREAK", diagnosticsHandler);
         } else {
-            handleSignal("HUP", handler);
-            handleSignal("QUIT", quitHandler);
+            handleSignal("HUP", exitHandler);
+            handleSignal("QUIT", diagnosticsHandler);
         }
     }
 
@@ -294,6 +293,12 @@ public void run() {
             } finally {
                 stateLock.unlock();
             }
+            if (currentApplication.isStarted()) {
+                // On CLI apps, SIGINT won't call io.quarkus.runtime.Application#stop(),
+                // making the awaitShutdown() below block the application termination process
+                // It should be a noop if called twice anyway
+                currentApplication.stop();
+            }
             currentApplication.awaitShutdown();
             System.out.flush();
             System.err.flush();
diff --git a/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java b/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java
index 31c8ad6175b..5e19392330d 100644
--- a/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java
+++ b/core/runtime/src/main/java/io/quarkus/runtime/logging/LoggingSetupRecorder.java
@@ -46,7 +46,7 @@
 @Recorder
 public class LoggingSetupRecorder {
 
-    private static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("win");
+    private static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows");
 
     /**
      * <a href="https://conemu.github.io">ConEmu</a> ANSI X3.64 support enabled,