commit f1417a7334806708d901d805b768bdbce6e74958
parent 12577b58c1ffd43ba43ca5b0a41c4b7c6131b47d
Author: MS <ms@taler.net>
Date: Thu, 28 Jan 2021 23:30:13 +0100
end gracefully when port isn't free
Diffstat:
4 files changed, 16 insertions(+), 25 deletions(-)
diff --git a/debian/libeufin/etc/systemd/system/nexus.service b/debian/libeufin/etc/systemd/system/nexus.service
@@ -1,11 +0,0 @@
-[Unit]
-Description=LibEuFin Nexus service.
-
-[Service]
-EnvironmentFile=/etc/libeufin/libeufinenv.conf
-User=libeufin
-ExecStart=/usr/bin/libeufin-nexus serve --port=$LIBEUFIN_NEXUS_PORT
-Restart=on-failure
-
-[Install]
-WantedBy=multi-user.target
diff --git a/debian/libeufin/etc/systemd/system/sandbox.service b/debian/libeufin/etc/systemd/system/sandbox.service
@@ -1,11 +0,0 @@
-[Unit]
-Description=LibEuFin Sandbox service.
-
-[Service]
-EnvironmentFile=/etc/libeufin/libeufinenv.conf
-User=libeufin
-ExecStart=/usr/bin/libeufin-sandbox serve --port=$LIBEUFIN_SANDBOX_PORT
-Restart=on-failure
-
-[Install]
-WantedBy=multi-user.target
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/server/NexusServer.kt
@@ -50,7 +50,9 @@ import tech.libeufin.nexus.bankaccount.*
import tech.libeufin.nexus.ebics.*
import tech.libeufin.nexus.iso20022.CamtBankAccountEntry
import tech.libeufin.util.*
+import java.net.BindException
import java.net.URLEncoder
+import kotlin.system.exitProcess
/**
* Return facade state depending on the type.
@@ -1040,5 +1042,10 @@ fun serverMain(dbName: String, host: String, port: Int) {
}
}
logger.info("LibEuFin Nexus running on port $port")
- server.start(wait = true)
+ try {
+ server.start(wait = true)
+ } catch (e: BindException) {
+ logger.error(e.message)
+ exitProcess(1)
+ }
}
diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt
@@ -83,8 +83,10 @@ import tech.libeufin.sandbox.BankAccountTransactionsTable.pmtInfId
import tech.libeufin.util.*
import tech.libeufin.util.ebics_h004.EbicsResponse
import tech.libeufin.util.ebics_h004.EbicsTypes
+import java.net.BindException
import java.util.*
import kotlin.random.Random
+import kotlin.system.exitProcess
val SANDBOX_DB_ENV_VAR_NAME = "LIBEUFIN_SANDBOX_DB_CONNECTION"
private val logger: Logger = LoggerFactory.getLogger("tech.libeufin.sandbox")
@@ -238,7 +240,6 @@ fun serverMain(dbName: String, port: Int) {
HttpStatusCode.InternalServerError
)
}
-
exception<EbicsRequestError> { cause ->
val resp = EbicsResponse.createForUploadWithError(
cause.errorText,
@@ -570,5 +571,10 @@ fun serverMain(dbName: String, port: Int) {
}
}
logger.info("LibEuFin Sandbox running on port $port")
- server.start(wait = true)
+ try {
+ server.start(wait = true)
+ } catch (e: BindException) {
+ logger.error(e.message)
+ exitProcess(1)
+ }
}
\ No newline at end of file