Skip to content

Commit 95b1794

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents 54f660b + 1748933 commit 95b1794

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

controller-runtime/src/main/kotlin/app/simplecloud/controller/runtime/ControllerRuntime.kt

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import io.grpc.Server
1919
import io.grpc.ServerBuilder
2020
import kotlinx.coroutines.*
2121
import org.apache.logging.log4j.LogManager
22-
import kotlin.concurrent.thread
2322

2423
class ControllerRuntime(
2524
private val controllerStartCommand: ControllerStartCommand
@@ -45,13 +44,23 @@ class ControllerRuntime(
4544
private val server = createGrpcServer()
4645
private val pubSubServer = createPubSubGrpcServer()
4746

48-
fun start() {
47+
suspend fun start() {
4948
setupDatabase()
5049
startPubSubGrpcServer()
5150
startGrpcServer()
5251
startReconciler()
5352
loadGroups()
5453
loadServers()
54+
55+
suspendCancellableCoroutine<Unit> { continuation ->
56+
Runtime.getRuntime().addShutdownHook(Thread {
57+
server.shutdown()
58+
continuation.resume(Unit) { cause, _, _ ->
59+
logger.info("Server shutdown due to: $cause")
60+
}
61+
})
62+
}
63+
5564
}
5665

5766
private fun setupDatabase() {
@@ -71,17 +80,27 @@ class ControllerRuntime(
7180

7281
private fun startGrpcServer() {
7382
logger.info("Starting gRPC server...")
74-
thread {
75-
server.start()
76-
server.awaitTermination()
83+
CoroutineScope(Dispatchers.Default).launch {
84+
try {
85+
server.start()
86+
server.awaitTermination()
87+
} catch (e: Exception) {
88+
logger.error("Error in gRPC server", e)
89+
throw e
90+
}
7791
}
7892
}
7993

8094
private fun startPubSubGrpcServer() {
8195
logger.info("Starting pubsub gRPC server...")
82-
thread {
83-
pubSubServer.start()
84-
pubSubServer.awaitTermination()
96+
CoroutineScope(Dispatchers.Default).launch {
97+
try {
98+
pubSubServer.start()
99+
pubSubServer.awaitTermination()
100+
} catch (e: Exception) {
101+
logger.error("Error in gRPC server", e)
102+
throw e
103+
}
85104
}
86105
}
87106

controller-runtime/src/main/kotlin/app/simplecloud/controller/runtime/launcher/ControllerStartCommand.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package app.simplecloud.controller.runtime.launcher
33
import app.simplecloud.controller.runtime.ControllerRuntime
44
import app.simplecloud.controller.shared.secret.AuthFileSecretFactory
55
import app.simplecloud.metrics.internal.api.MetricsCollector
6-
import com.github.ajalt.clikt.core.CliktCommand
6+
import com.github.ajalt.clikt.command.SuspendingCliktCommand
77
import com.github.ajalt.clikt.core.context
88
import com.github.ajalt.clikt.parameters.options.default
99
import com.github.ajalt.clikt.parameters.options.defaultLazy
@@ -18,7 +18,7 @@ import java.nio.file.Path
1818

1919
class ControllerStartCommand(
2020
private val metricsCollector: MetricsCollector?
21-
) : CliktCommand() {
21+
) : SuspendingCliktCommand() {
2222

2323
init {
2424
context {
@@ -54,7 +54,7 @@ class ControllerStartCommand(
5454
.boolean()
5555
.default(true)
5656

57-
override fun run() {
57+
override suspend fun run() {
5858
if (trackMetrics) {
5959
metricsCollector?.start()
6060
}

controller-runtime/src/main/kotlin/app/simplecloud/controller/runtime/launcher/Launcher.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package app.simplecloud.controller.runtime.launcher
22

33
import app.simplecloud.metrics.internal.api.MetricsCollector
4+
import com.github.ajalt.clikt.command.main
45
import org.apache.logging.log4j.LogManager
56

67

gradle/libs.versions.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
kotlin = "2.0.20"
33
kotlinCoroutines = "1.9.0"
44
shadow = "8.3.3"
5-
log4j = "2.20.0"
5+
log4j = "2.22.0"
6+
slf4j = "2.0.16"
67
protobuf = "3.25.2"
78
grpc = "1.61.0"
89
grpcKotlin = "1.4.1"
@@ -12,7 +13,7 @@ simplecloud-metrics = "1.0.0"
1213
jooq = "3.19.3"
1314
configurate = "4.1.2"
1415
sqliteJdbc = "3.44.1.0"
15-
clikt = "4.3.0"
16+
clikt = "5.0.1"
1617
sonatypeCentralPortalPublisher = "1.2.3"
1718
spotifyCompletableFutures = "0.3.6"
1819

@@ -24,6 +25,7 @@ kotlinCoroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", v
2425
log4jCore = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j" }
2526
log4jApi = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j" }
2627
log4jSlf4j = { module = "org.apache.logging.log4j:log4j-slf4j-impl", version.ref = "log4j" }
28+
slf4jApi = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" } # Add this
2729

2830
protobufKotlin = { module = "com.google.protobuf:protobuf-kotlin", version.ref = "protobuf" }
2931

@@ -54,7 +56,8 @@ spotifyCompletableFutures = { module = "com.spotify:completable-futures", versio
5456
log4j = [
5557
"log4jCore",
5658
"log4jApi",
57-
"log4jSlf4j"
59+
"log4jSlf4j",
60+
"slf4jApi"
5861
]
5962
proto = [
6063
"protobufKotlin",

0 commit comments

Comments
 (0)