view doesn't need smtp loop; some cleanup

This commit is contained in:
Claude Brisson
2023-06-12 09:27:59 +02:00
parent 2ae8657b83
commit 231d90171b
2 changed files with 13 additions and 10 deletions

View File

@@ -72,12 +72,6 @@ class WebappManager : ServletContextListener, ServletContextAttributeListener, H
// fail to correctly implement SSL...
disableSSLCertificateChecks()
// start smtp loop
if (properties.containsKey("smtp.host")) {
registerService("smtp", SmtpLoop(properties))
startService("smtp")
}
} catch (ioe: IOException) {
logger.error("webapp initialization error", ioe)
}

View File

@@ -35,6 +35,11 @@ import java.util.regex.Pattern
fun main(vararg args: String) {
try {
// register a shutdown hook for any global necessary cleanup
Runtime.getRuntime().addShutdownHook(object: Thread() {
override fun run() { cleanup() }
})
// read default properties and provided ones, if any
readProperties()
// extract war files from main archive
@@ -47,8 +52,13 @@ fun main(vararg args: String) {
}
private val tmp = System.getProperty("java.io.tmpdir")
private val webapps = Path.of("${tmp}/pairgoth/webapps")
private val version = "1.0-SNAPSHOT" // TODO CB
private fun cleanup() {
FileUtils.deleteDirectory(webapps.toFile())
}
private fun readProperties() {
val defaultProps = getResource("/server.default.properties") ?: throw Error("missing default server properties")
defaultProps.openStream().use {
@@ -76,9 +86,8 @@ private fun readProperties() {
private fun extractWarFiles() {
// val jarLocation = object{}::class.java.protectionDomain.codeSource.location
// prepare output directory
val targetPath = Path.of("${tmp}/pairgoth/webapps")
FileUtils.deleteDirectory(targetPath.toFile())
Files.createDirectories(targetPath)
FileUtils.deleteDirectory(webapps.toFile())
Files.createDirectories(webapps)
// extract wars
val webappsFolderURL = getResource("/META-INF/webapps") ?: throw Error("webapps not found")
@@ -89,7 +98,7 @@ private fun extractWarFiles() {
}.forEach { entry ->
if (!entry.isDirectory) {
jarFile.getInputStream(entry).use { entryInputStream ->
Files.copy(entryInputStream, targetPath.resolve(entry.name.removePrefix("META-INF/webapps/")))
Files.copy(entryInputStream, webapps.resolve(entry.name.removePrefix("META-INF/webapps/")))
}
}
}