Log server start

This commit is contained in:
Christoph Hagen 2023-11-27 18:17:00 +01:00
parent a217db1945
commit 7f1b9a5d96
2 changed files with 11 additions and 3 deletions

View File

@ -7,7 +7,7 @@ var deviceManager: DeviceManager!
private var provider: VaporMetricProvider!
private var asyncScheduler: AsyncScheduler = MultiThreadedEventLoopGroup(numberOfThreads: 2)
private var asyncScheduler = MultiThreadedEventLoopGroup(numberOfThreads: 2)
private let df: DateFormatter = {
let df = DateFormatter()
@ -57,7 +57,8 @@ public func configure(_ app: Application) throws {
}
print("[\(df.string(from: Date()))] Server started")
log("[\(df.string(from: Date()))] Server started")
// Gracefully shut down by closing potentially open socket
// Must be done after app is running, otherwise error is thrown
DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + .seconds(5)) {
@ -70,6 +71,10 @@ public func configure(_ app: Application) throws {
}
}
public func shutdown() {
try? asyncScheduler.syncShutdownGracefully()
}
private func loadKeys(at url: URL) throws -> (deviceKey: Data, remoteKey: Data) {
let authContent: [Data] = try String(contentsOf: url)
.trimmingCharacters(in: .whitespacesAndNewlines)

View File

@ -4,7 +4,10 @@ import Vapor
var env = Environment.production //.detect()
try LoggingSystem.bootstrap(from: &env)
let app = Application(env)
defer { app.shutdown() }
defer {
app.shutdown()
shutdown()
}
try configure(app)
try app.run()