Compare commits
No commits in common. "1e649f297e25add6033694a17eb28ac296adeb18" and "62ae594e060c9e5500790d542dd6b32debc72ad9" have entirely different histories.
1e649f297e
...
62ae594e06
@ -2,7 +2,7 @@
|
|||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "Schafkopf-Server",
|
name: "SchafkopfServer",
|
||||||
platforms: [
|
platforms: [
|
||||||
.macOS(.v12)
|
.macOS(.v12)
|
||||||
],
|
],
|
||||||
|
@ -33,22 +33,6 @@ struct Configuration {
|
|||||||
|
|
||||||
/// The authentication tokens to access the metrics
|
/// The authentication tokens to access the metrics
|
||||||
let monitoringTokens: Set<String>
|
let monitoringTokens: Set<String>
|
||||||
|
|
||||||
/// The path to the folder where the metric logs are stored
|
|
||||||
///
|
|
||||||
/// If no path is provided, then a folder `logs` in the resources directory is created
|
|
||||||
/// If the path is relative, then it is assumed relative to the resources directory
|
|
||||||
let logPath: String?
|
|
||||||
|
|
||||||
func logURL(possiblyRelativeTo resourcesDirectory: URL) -> URL {
|
|
||||||
guard let logPath else {
|
|
||||||
return resourcesDirectory.appendingPathComponent("logs")
|
|
||||||
}
|
|
||||||
guard !logPath.hasPrefix("/") else {
|
|
||||||
return .init(fileURLWithPath: logPath)
|
|
||||||
}
|
|
||||||
return resourcesDirectory.appendingPathComponent(logPath)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Configuration {
|
extension Configuration {
|
||||||
|
@ -29,12 +29,8 @@ public func configure(_ app: Application) throws {
|
|||||||
|
|
||||||
private func configureAsync(_ app: Application) async throws {
|
private func configureAsync(_ app: Application) async throws {
|
||||||
let storageFolder = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
let storageFolder = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
||||||
|
|
||||||
let configPath = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
|
||||||
.appendingPathComponent("config.json")
|
|
||||||
let configuration = try Configuration(loadFromUrl: configPath)
|
|
||||||
|
|
||||||
let logFolder = configuration.logURL(possiblyRelativeTo: storageFolder)
|
let logFolder = storageFolder.appendingPathComponent("logs")
|
||||||
let monitor = MetricObserver(
|
let monitor = MetricObserver(
|
||||||
logFileFolder: logFolder,
|
logFileFolder: logFolder,
|
||||||
logMetricId: "schafkopf.log")
|
logMetricId: "schafkopf.log")
|
||||||
@ -47,6 +43,20 @@ private func configureAsync(_ app: Application) async throws {
|
|||||||
|
|
||||||
_ = try? await status.update(.initializing)
|
_ = try? await status.update(.initializing)
|
||||||
|
|
||||||
|
let configPath = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
||||||
|
.appendingPathComponent("config.json")
|
||||||
|
let configuration: Configuration
|
||||||
|
|
||||||
|
do {
|
||||||
|
configuration = try Configuration(loadFromUrl: configPath)
|
||||||
|
} catch {
|
||||||
|
_ = try? await status.update(.initializationFailure)
|
||||||
|
await monitor.log("Failed to read configuration: \(error)")
|
||||||
|
// Note: If configuration can't be loaded, then the server will run on the wrong port
|
||||||
|
// and access to metrics is impossible, since no tokens are loaded
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
app.http.server.configuration.port = configuration.serverPort
|
app.http.server.configuration.port = configuration.serverPort
|
||||||
|
|
||||||
// Set target environment
|
// Set target environment
|
||||||
|
Loading…
Reference in New Issue
Block a user