Skip to content
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

autocreate default config if none was found #781

Merged
merged 3 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions LavalinkServer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ tasks {
)

filter(ReplaceTokens::class, mapOf("tokens" to tokens))
copy {
from("application.yml.example")
into("$buildDir/resources/main")
}
}

// https://stackoverflow.com/questions/41444916/multiple-artifacts-issue-with-deploying-zip-to-nexus
Expand Down
20 changes: 20 additions & 0 deletions LavalinkServer/src/main/java/lavalink/server/Launcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.springframework.context.ConfigurableApplicationContext
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.FilterType
import org.springframework.core.io.DefaultResourceLoader
import java.io.File
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
Expand Down Expand Up @@ -120,6 +121,25 @@ object Launcher {
println(getVersionInfo(indentation = "", vanity = false))
return
}

val config = File("./application.yml")
if (!config.exists()) {
log.info("No application.yml found, creating one...")
Launcher::class.java.getResource("/application.yml.example")?.let {
it.openStream()?.use {
if (!config.createNewFile()) {
log.error("Unable to create application.yml")
return
}
config.outputStream().use { out ->
it.copyTo(out)
}
}
} ?: run {
topi314 marked this conversation as resolved.
Show resolved Hide resolved
log.error("Unable to find application.yml.example in resources")
}
}

val parent = launchPluginBootstrap()
log.info("You can safely ignore the big red warning about illegal reflection. See https://github.com/freyacodes/Lavalink/issues/295")
launchMain(parent, args)
Expand Down