From 231d90171b7b16eea3ddac44f2cc36dcca0cdf79 Mon Sep 17 00:00:00 2001 From: Claude Brisson Date: Mon, 12 Jun 2023 09:27:59 +0200 Subject: [PATCH] view doesn't need smtp loop; some cleanup --- .../org/jeudego/pairgoth/web/WebappManager.kt | 6 ------ .../jeudego/pairgoth/application/Pairgoth.kt | 17 +++++++++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/view-webapp/src/main/kotlin/org/jeudego/pairgoth/web/WebappManager.kt b/view-webapp/src/main/kotlin/org/jeudego/pairgoth/web/WebappManager.kt index ccb3987..16566f0 100644 --- a/view-webapp/src/main/kotlin/org/jeudego/pairgoth/web/WebappManager.kt +++ b/view-webapp/src/main/kotlin/org/jeudego/pairgoth/web/WebappManager.kt @@ -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) } diff --git a/webserver/src/main/kotlin/org/jeudego/pairgoth/application/Pairgoth.kt b/webserver/src/main/kotlin/org/jeudego/pairgoth/application/Pairgoth.kt index e2e3c93..83d736e 100644 --- a/webserver/src/main/kotlin/org/jeudego/pairgoth/application/Pairgoth.kt +++ b/webserver/src/main/kotlin/org/jeudego/pairgoth/application/Pairgoth.kt @@ -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/"))) } } }