mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Try to shutdown cleanly when server stops or SIGINT is received
This commit is contained in:
@@ -106,4 +106,8 @@ public class BriarService {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
lifecycleManager.stopServices();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ import io.javalin.Javalin;
|
||||
import static io.javalin.ApiBuilder.get;
|
||||
import static io.javalin.ApiBuilder.path;
|
||||
import static io.javalin.ApiBuilder.post;
|
||||
import static io.javalin.event.EventType.SERVER_START_FAILED;
|
||||
import static io.javalin.event.EventType.SERVER_STOPPED;
|
||||
import static java.lang.Runtime.getRuntime;
|
||||
|
||||
@Immutable
|
||||
@Singleton
|
||||
@@ -35,6 +38,7 @@ public class Router {
|
||||
|
||||
public void start() {
|
||||
briarService.start();
|
||||
getRuntime().addShutdownHook(new Thread(briarService::stop));
|
||||
|
||||
Javalin app = Javalin.create()
|
||||
.port(7000)
|
||||
@@ -42,6 +46,8 @@ public class Router {
|
||||
.enableStandardRequestLogging()
|
||||
.enableRouteOverview("/")
|
||||
.enableDynamicGzip()
|
||||
.event(SERVER_START_FAILED, event -> briarService.stop())
|
||||
.event(SERVER_STOPPED, event -> briarService.stop())
|
||||
.start();
|
||||
|
||||
app.routes(() -> {
|
||||
|
||||
Reference in New Issue
Block a user