-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/launcher #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TheBjoRedCraft
wants to merge
28
commits into
version/26.1
Choose a base branch
from
feat/launcher
base: version/26.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat/launcher #47
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
a6f0150
feat: implement core launcher with Redis integration and server state…
TheBjoRedCraft 1e8e3ef
refactor: remove Redis integration and simplify server state management
TheBjoRedCraft 5b62e34
refactor: remove Redis integration and simplify server state management
TheBjoRedCraft d2e1235
refactor: replace logger with console output and improve server state…
TheBjoRedCraft db5bba6
refactor: enhance server launch process and state management
TheBjoRedCraft 16df0b5
feat: implement plugin updater with GitHub integration and auto-updat…
TheBjoRedCraft fb103bf
refactor: clean up CoreLauncher and GitHubClient for improved readabi…
TheBjoRedCraft 818fdba
feat: enhance plugin updater with improved asset matching and special…
TheBjoRedCraft bdb5c51
feat: optimize plugin update checks using coroutines for improved per…
TheBjoRedCraft 303298e
feat: update log prefix in CoreLauncher to include timestamp for bett…
TheBjoRedCraft 6c10e6f
feat: update log prefix in CoreLauncher to use braces for better form…
TheBjoRedCraft 11af783
feat: update log prefix in CoreLauncher to use a new date-time format…
TheBjoRedCraft 637bc4d
feat: update log prefix in CoreLauncher to use square brackets for be…
TheBjoRedCraft 77c6026
feat: refactor CoreLauncher to use lazy config initialization and imp…
TheBjoRedCraft 3196f48
feat: add support for core launcher integration and update event hand…
TheBjoRedCraft 67a3972
feat: add surfCoreApiCommon dependency to build configuration
TheBjoRedCraft 5dff79a
feat: enhance VelocityRedisListener with service status handling and …
TheBjoRedCraft 3682ce4
feat: add toggle command for service status message notifications
TheBjoRedCraft f698864
feat: integrate Redis for service status monitoring and update handling
TheBjoRedCraft f6f0dea
Merge remote-tracking branch 'origin/version/26.1' into feat/launcher
TheBjoRedCraft cb6dee9
Merge remote-tracking branch 'origin/version/26.1' into feat/launcher
TheBjoRedCraft 372e0d5
feat: add publishing configuration for slneReleases repository
TheBjoRedCraft 0bf67d8
feat: enhance server online status handling and support for velocity-…
TheBjoRedCraft 889a474
Merge branch 'version/26.1' into feat/launcher
TheBjoRedCraft 820b4cb
Potential fix for pull request finding
TheBjoRedCraft fe3bd78
Potential fix for pull request finding
TheBjoRedCraft 9f1d839
Potential fix for pull request finding
TheBjoRedCraft 5faed67
Potential fix for pull request finding
TheBjoRedCraft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| kotlin.code.style=official | ||
| kotlin.stdlib.default.dependency=false | ||
| org.gradle.parallel=true | ||
| version=2.3.2 | ||
| version=2.4.0 |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| #Sun Apr 05 17:57:20 CEST 2026 | ||
| distributionBase=GRADLE_USER_HOME | ||
| distributionPath=wrapper/dists | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip | ||
| distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip | ||
| networkTimeout=10000 | ||
| retries=0 | ||
| retryBackOffMs=500 | ||
| validateDistributionUrl=true | ||
| zipStoreBase=GRADLE_USER_HOME | ||
| zipStorePath=wrapper/dists |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...on/redis/event/SurfEventFireRedisEvent.kt → ...on/event/redis/SurfEventFireRedisEvent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...pi-common/src/main/kotlin/dev/slne/surf/core/api/common/server/state/SurfServiceStatus.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package dev.slne.surf.core.api.common.server.state | ||
|
|
||
| enum class SurfServiceStatus { | ||
| UNREACHABLE, | ||
| CRASHED | ||
| } |
2 changes: 1 addition & 1 deletion
2
...-common/src/main/kotlin/dev/slne/surf/core/core/common/event/LocalSurfEventBusListener.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
surf-core-launcher/surf-core-launcher-api/build.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import dev.slne.surf.api.gradle.util.slneReleases | ||
|
|
||
| plugins { | ||
| id("dev.slne.surf.api.gradle.core") | ||
| } | ||
|
|
||
| surfCoreApi { | ||
| withSurfRedis() | ||
| } | ||
|
|
||
| dependencies { | ||
| api(projects.surfCoreApi.surfCoreApiCommon) | ||
| } | ||
|
|
||
| publishing { | ||
| repositories { | ||
| slneReleases() | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
...rf-core-launcher-api/src/main/kotlin/dev/slne/surf/core/launcher/api/LauncherConstants.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package dev.slne.surf.core.launcher.api | ||
|
|
||
| object LauncherConstants { | ||
| const val PROPERTY_LAUNCHED_BY_CORE = "LAUNCHED_BY_CORE" | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
...cher-api/src/main/kotlin/dev/slne/surf/core/launcher/api/redis/ServiceStatusRedisEvent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package dev.slne.surf.core.launcher.api.redis | ||
|
|
||
| import dev.slne.surf.core.api.common.server.state.SurfServiceStatus | ||
| import dev.slne.surf.redis.event.RedisEvent | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class ServiceStatusRedisEvent( | ||
| val serviceName: String, | ||
| val status: SurfServiceStatus | ||
| ) : RedisEvent() |
21 changes: 21 additions & 0 deletions
21
surf-core-launcher/surf-core-launcher-server/build.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| plugins { | ||
| id("dev.slne.surf.api.gradle.standalone") | ||
| } | ||
|
|
||
| dependencies { | ||
| api(projects.surfCoreLauncher.surfCoreLauncherApi) | ||
| implementation(projects.surfCoreApi.surfCoreApiCommon) | ||
| implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.17.2") | ||
| implementation("dev.slne.surf.redis:surf-redis-standalone:1.6.1") | ||
| } | ||
|
|
||
| tasks.jar { | ||
| manifest { | ||
| attributes["Main-Class"] = "dev.slne.surf.core.launcher.server.CoreLauncherKt" | ||
| } | ||
| } | ||
|
|
||
| tasks.shadowJar { | ||
| exclude("okio/**") | ||
| exclude("io/netty/**") | ||
| } |
186 changes: 186 additions & 0 deletions
186
...f-core-launcher-server/src/main/kotlin/dev/slne/surf/core/launcher/server/CoreLauncher.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| package dev.slne.surf.core.launcher.server | ||
|
|
||
| import dev.slne.surf.api.standalone.SurfApiStandaloneBootstrap | ||
| import dev.slne.surf.core.api.common.event.SurfServerStartEvent | ||
| import dev.slne.surf.core.api.common.event.redis.SurfEventFireRedisEvent | ||
| import dev.slne.surf.core.launcher.api.LauncherConstants | ||
| import dev.slne.surf.core.launcher.server.config.CoreLauncherConfig | ||
| import dev.slne.surf.core.launcher.server.ping.MinecraftServerPinger | ||
| import dev.slne.surf.core.launcher.server.updater.process.PluginUpdater | ||
| import dev.slne.surf.redis.RedisApi | ||
| import dev.slne.surf.redis.StandaloneRedisInstance | ||
| import kotlinx.coroutines.* | ||
| import kotlinx.coroutines.flow.MutableStateFlow | ||
| import java.nio.file.Path | ||
| import java.time.LocalDateTime | ||
| import java.time.format.DateTimeFormatter | ||
| import java.util.concurrent.TimeUnit | ||
| import java.util.concurrent.atomic.AtomicBoolean | ||
| import kotlin.io.path.Path | ||
| import kotlin.time.Duration.Companion.seconds | ||
|
|
||
| private val secondDateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss") | ||
|
|
||
| val LOG_PREFIX | ||
| get() = | ||
| "\u001B[0;91m[${ | ||
| LocalDateTime.now().format(secondDateTimeFormatter) | ||
| } CoreLauncher]\u001B[0m" | ||
|
|
||
| object CoreLauncher { | ||
| private val shuttingDown = AtomicBoolean(false) | ||
| lateinit var serverProcess: Process | ||
|
|
||
| private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO) | ||
| private var monitorJob: Job? = null | ||
| private val redisInstance = StandaloneRedisInstance( | ||
| name = "surf-core-launcher", | ||
| configPath = findRedisPluginPath() | ||
| ?: error("Could not find Redis plugin configuration path, cannot start Redis instance") | ||
| ) | ||
| lateinit var redisApi: RedisApi | ||
|
|
||
| val serverOnline = MutableStateFlow(false) | ||
|
|
||
| val config by lazy { | ||
| CoreLauncherConfig.getConfig() | ||
| } | ||
|
|
||
| suspend fun launch() = withContext(Dispatchers.IO) { | ||
| SurfApiStandaloneBootstrap.bootstrap() | ||
| SurfApiStandaloneBootstrap.enable() | ||
|
|
||
| println("$LOG_PREFIX Initializing Redis instance...") | ||
|
|
||
| redisInstance.create() | ||
| redisApi = RedisApi.create() | ||
| redisApi.freezeAndConnect() | ||
|
|
||
| println("$LOG_PREFIX Redis instance initialized and connected") | ||
|
|
||
| if (config.autoUpdateSurfPlugins) { | ||
| println("$LOG_PREFIX Searching plugin updates...") | ||
|
|
||
| withTimeoutOrNull(20.seconds) { | ||
| if (config.personalAccessToken.isBlank()) { | ||
| println("$LOG_PREFIX No GitHub personal access token provided, skipping plugin update check") | ||
| return@withTimeoutOrNull | ||
| } | ||
|
|
||
| PluginUpdater.start() | ||
| } | ||
| ?: println("$LOG_PREFIX Plugin update check timed out after 20 seconds, continuing with server startup") | ||
| } | ||
|
|
||
| println("$LOG_PREFIX Starting Minecraft Server...") | ||
|
|
||
| val command = buildStartupCommand() | ||
|
|
||
| serverProcess = ProcessBuilder(command) | ||
| .redirectInput(ProcessBuilder.Redirect.INHERIT) | ||
| .redirectOutput(ProcessBuilder.Redirect.PIPE) | ||
| .redirectError(ProcessBuilder.Redirect.INHERIT) | ||
| .start() | ||
|
|
||
| println("$LOG_PREFIX Server process started") | ||
|
|
||
| redisApi.publishEvent( | ||
| SurfEventFireRedisEvent( | ||
| SurfServerStartEvent( | ||
| serverName = config.serverName | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| monitorJob = scope.launch { | ||
| launch { | ||
| serverProcess.inputStream.bufferedReader().forEachLine { line -> | ||
| println(line) | ||
|
|
||
| if (line.contains( | ||
| config.startedMessage, | ||
| ignoreCase = true | ||
| ) | ||
| ) { | ||
| serverOnline.value = true | ||
| println("$LOG_PREFIX Server is now online.") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| MinecraftServerPinger.monitor(serverProcess) | ||
| } | ||
| } | ||
|
|
||
| suspend fun shutdown() { | ||
| if (!shuttingDown.compareAndSet(false, true)) { | ||
| return | ||
| } | ||
|
|
||
| serverOnline.value = true | ||
|
|
||
| println("$LOG_PREFIX Shutting down launcher/server...") | ||
| println("$LOG_PREFIX Disconnecting Redis instance...") | ||
|
|
||
| redisApi.disconnect() | ||
| redisInstance.shutdown() | ||
| println("$LOG_PREFIX Redis instance disconnected and shutdown") | ||
|
|
||
| monitorJob?.cancelAndJoin() | ||
|
|
||
| if (::serverProcess.isInitialized && serverProcess.isAlive) { | ||
| serverProcess.destroy() | ||
|
|
||
| if (!serverProcess.waitFor(45, TimeUnit.SECONDS)) { | ||
| println("$LOG_PREFIX Server did not stop within 45 seconds") | ||
| } | ||
| } | ||
|
|
||
| scope.cancel() | ||
| } | ||
|
|
||
| fun isShuttingDown(): Boolean = shuttingDown.get() | ||
|
|
||
| private fun buildStartupCommand(): List<String> { | ||
| val base = config.serverStartupCommand | ||
|
|
||
| val parts = Regex("""[^\s"]+|"([^"]*)"""") | ||
| .findAll(base) | ||
| .map { it.value.replace("\"", "") } | ||
| .toMutableList() | ||
|
|
||
| val flag = "-D${LauncherConstants.PROPERTY_LAUNCHED_BY_CORE}" | ||
|
|
||
| if (parts.none { it == flag }) { | ||
| parts.add(1, flag) | ||
| } | ||
|
TheBjoRedCraft marked this conversation as resolved.
|
||
|
|
||
| return parts | ||
| } | ||
|
|
||
| private fun findRedisPluginPath(): Path? { | ||
| val possiblePaths = listOf( | ||
| Path("plugins", "surf-redis-paper"), | ||
| Path("plugins", "surf-redis-velocity") | ||
| ) | ||
|
|
||
| return possiblePaths.firstOrNull { path -> | ||
| path.toFile().exists() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| suspend fun main(args: Array<String>) { | ||
| Runtime.getRuntime().addShutdownHook(Thread { | ||
| runBlocking { | ||
| CoreLauncher.shutdown() | ||
| SurfApiStandaloneBootstrap.shutdown() | ||
| } | ||
| }) | ||
|
|
||
| CoreLauncher.launch() | ||
| CoreLauncher.serverProcess.waitFor() | ||
|
|
||
| CoreLauncher.shutdown() | ||
| SurfApiStandaloneBootstrap.shutdown() | ||
| } | ||
8 changes: 8 additions & 0 deletions
8
...cher-server/src/main/kotlin/dev/slne/surf/core/launcher/server/CoreLauncherEnvironment.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package dev.slne.surf.core.launcher.server | ||
|
|
||
| object CoreLauncherEnvironment { | ||
| val MC_MEMORY_MAX = | ||
| System.getenv("SERVER_MEMORY") ?: error("SERVER_MEMORY environment variable is not set") | ||
| val SERVER_PORT = System.getenv("SERVER_PORT")?.toInt() | ||
| ?: error("SERVER_PORT environment variable is not set or is not a valid integer") | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.