libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit a09b84c636f6332b219480ca620060eb6ca13758
parent 15ab519ed54c0d5ca5840c175f9aa0642a6ccf87
Author: Antoine A <>
Date:   Wed,  1 May 2024 13:47:06 +0900

nexus: add libeufin-nexus-httpd service

Diffstat:
Mcommon/src/main/kotlin/Cli.kt | 2++
Adebian/libeufin-nexus.libeufin-nexus-httpd.service | 14++++++++++++++
Mdebian/libeufin-nexus.target | 1+
Mdebian/rules | 3++-
Mnexus/src/main/kotlin/tech/libeufin/nexus/Main.kt | 24++++++++++++++++++++++++
Mnexus/src/test/kotlin/CliTest.kt | 13+++++++++++++
6 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/common/src/main/kotlin/Cli.kt b/common/src/main/kotlin/Cli.kt @@ -70,6 +70,8 @@ fun cliCmd(logger: Logger, level: Level, lambda: suspend () -> Unit) { } }) } + } catch (e: ProgramResult) { + throw e } catch (e: Throwable) { e.fmtLog(logger) throw ProgramResult(1) diff --git a/debian/libeufin-nexus.libeufin-nexus-httpd.service b/debian/libeufin-nexus.libeufin-nexus-httpd.service @@ -0,0 +1,14 @@ +[Unit] +Description=LibEuFin Nexus Server Service +After=postgres.service network.target +PartOf=libeufin-nexus.target + +[Service] +User=libeufin-nexus +ExecStart=/usr/bin/libeufin-nexus serve -c /etc/libeufin/libeufin-nexus.conf +ExecCondition=/usr/bin/libeufin-nexus serve -c /etc/libeufin/libeufin-nexus.conf --check +Restart=on-failure +RestartSec=1s + +[Install] +WantedBy=multi-user.target diff --git a/debian/libeufin-nexus.target b/debian/libeufin-nexus.target @@ -4,6 +4,7 @@ After=postgres.service network.target Wants=libeufin-nexus-ebics-fetch.service Wants=libeufin-nexus-ebics-submit.service +Wants=libeufin-nexus-httpd.service [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/debian/rules b/debian/rules @@ -39,12 +39,13 @@ override_dh_install: override_dh_installsystemd: # Need to specify units manually, since we have multiple # and dh_installsystemd by default only looks for "<package>.service". - dh_installsystemd -plibeufin-bank --name=libeufin-bank --no-start --no-enable --no-stop-on-upgrade + dh_installsystemd -plibeufin-bank --name=libeufin-bank.service --no-start --no-enable --no-stop-on-upgrade dh_installsystemd -plibeufin-bank --name=libeufin-bank-gc --no-start --no-enable --no-stop-on-upgrade dh_installsystemd -plibeufin-bank --name=libeufin-bank-gc.timer --no-start --no-enable --no-stop-on-upgrade dh_installsystemd -plibeufin-bank --name=libeufin-bank --no-start --no-enable --no-stop-on-upgrade dh_installsystemd -plibeufin-nexus --name=libeufin-nexus-ebics-submit --no-start --no-enable --no-stop-on-upgrade dh_installsystemd -plibeufin-nexus --name=libeufin-nexus-ebics-fetch --no-start --no-enable --no-stop-on-upgrade + dh_installsystemd -plibeufin-nexus --name=libeufin-nexus-httpd --no-start --no-enable --no-stop-on-upgrade dh_installsystemd -plibeufin-nexus --name=libeufin-nexus --no-start --no-enable --no-stop-on-upgrade # final invocation to generate daemon reload dh_installsystemd diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/Main.kt @@ -27,6 +27,7 @@ package tech.libeufin.nexus import com.github.ajalt.clikt.core.CliktCommand import com.github.ajalt.clikt.core.subcommands +import com.github.ajalt.clikt.core.ProgramResult import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.parameters.arguments.convert import com.github.ajalt.clikt.parameters.groups.provideDelegate @@ -148,9 +149,32 @@ class InitiatePayment: CliktCommand("Initiate an outgoing payment") { class Serve : CliktCommand("Run libeufin-nexus HTTP server", name = "serve") { private val common by CommonOption() + private val check by option().flag() override fun run() = cliCmd(logger, common.log) { val cfg = loadNexusConfig(common.config) + + if (check) { + // Check if the server is to be started + val apis = listOf( + cfg.wireGatewayApiCfg to "Wire Gateway API", + cfg.revenueApiCfg to "Revenue API" + ) + var startServer = false + for ((api, name) in apis) { + if (api != null) { + startServer = true + logger.info("$name is enabled: starting the server") + } + } + if (!startServer) { + logger.info("All APIs are disabled: not starting the server") + throw ProgramResult(1) + } else { + throw ProgramResult(0) + } + } + val dbCfg = cfg.config.dbConfig() val serverCfg = cfg.config.loadServerConfig("nexus-httpd") Database(dbCfg, cfg.currency).use { db -> diff --git a/nexus/src/test/kotlin/CliTest.kt b/nexus/src/test/kotlin/CliTest.kt @@ -118,4 +118,17 @@ class CliTest { nexusCmd.testErr("ebics-setup -c $conf", "Could not write client private keys at '$clientKeysPath': permission denied on '${clientKeysPath.parent}'") } } + + /** Test server check */ + @Test + fun serveCheck() { + val confs = listOf( + "mini" to 1, + "test" to 0 + ) + for ((conf, statusCode) in confs) { + val result = nexusCmd.test("serve --check -c conf/$conf.conf") + assertEquals(statusCode, result.statusCode) + } + } } \ No newline at end of file