Fix closing server with ^C

This commit is contained in:
Torsten Grote
2018-10-08 18:40:21 -03:00
parent 280f3ba1fc
commit e3686186ee

View File

@@ -16,12 +16,12 @@ import org.briarproject.briar.headless.event.WebSocketController
import org.briarproject.briar.headless.forums.ForumController import org.briarproject.briar.headless.forums.ForumController
import org.briarproject.briar.headless.messaging.MessagingController import org.briarproject.briar.headless.messaging.MessagingController
import java.lang.Runtime.getRuntime import java.lang.Runtime.getRuntime
import java.lang.System.exit
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import java.util.logging.Logger.getLogger import java.util.logging.Logger.getLogger
import javax.annotation.concurrent.Immutable import javax.annotation.concurrent.Immutable
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
import kotlin.system.exitProcess
@Immutable @Immutable
@Singleton @Singleton
@@ -47,8 +47,8 @@ constructor(
.port(port) .port(port)
.disableStartupBanner() .disableStartupBanner()
.enableCaseSensitiveUrls() .enableCaseSensitiveUrls()
.event(SERVER_START_FAILED) { stop() } .event(SERVER_START_FAILED) {serverStopped() }
.event(SERVER_STOPPED) { stop() } .event(SERVER_STOPPED) { serverStopped() }
if (debug) app.enableDebugLogging() if (debug) app.enableDebugLogging()
app.start() app.start()
@@ -99,10 +99,14 @@ constructor(
} }
} }
private fun serverStopped() {
stop()
exit(1)
}
private fun stop() { private fun stop() {
if (!stopped.getAndSet(true)) { if (!stopped.getAndSet(true)) {
briarService.stop() briarService.stop()
exitProcess(0)
} }
} }