taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

commit 431cef0b0ccdb5a397152b186043fa9a2f606f43
parent b826430a32e7a8c9f909ef072658329977a15e93
Author: Antoine A <>
Date:   Tue, 30 Dec 2025 11:51:30 +0100

common: support explicit systemd SERVE config

Diffstat:
Mcommon/taler-api/src/config.rs | 3+++
Mcommon/taler-api/src/lib.rs | 75+++++++++++++++++++++++++++++++++++++++------------------------------------
Ddebian/etc/taler-cyclos/conf.d/cyclos-htppd.conf | 9---------
Adebian/etc/taler-cyclos/conf.d/cyclos-httpd.conf | 12++++++++++++
Mdebian/etc/taler-magnet-bank/conf.d/magnet-bank-httpd.conf | 3+++
5 files changed, 57 insertions(+), 45 deletions(-)

diff --git a/common/taler-api/src/config.rs b/common/taler-api/src/config.rs @@ -105,6 +105,9 @@ impl Serve { let path = sect.path("UNIXPATH").require()?; let permission = sect.unix_mode("UNIXPATH_MODE").require()?; Ok::<Serve, ValueErr>(Serve::Unix { path, permission }) + }, + "systemd" => { + Ok::<Serve, ValueErr>(Serve::Systemd) } ) .require() diff --git a/common/taler-api/src/lib.rs b/common/taler-api/src/lib.rs @@ -36,50 +36,53 @@ pub enum Serve { path: String, permission: Permissions, }, + Systemd, } impl Serve { /// Resolve listener from a config and environment fn resolve(&self) -> Result<Listener, std::io::Error> { - // Check if systemd is passing a socket - let mut listenfd = ListenFd::from_env(); - if let Ok(Some(unix)) = listenfd.take_unix_listener(0) { - info!(target: "api", - "Server listening on activated unix socket {:?}", - unix.local_addr()? - ); - unix.set_nonblocking(true)?; - Ok(Listener::Unix(UnixListener::from_std(unix)?)) - } else if let Ok(Some(tcp)) = listenfd.take_tcp_listener(0) { - info!(target: "api", - "Server listening on activated TCP socket {:?}", - tcp.local_addr()? - ); - tcp.set_nonblocking(true)?; - Ok(Listener::Tcp(TcpListener::from_std(tcp)?)) - } else { - match self { - Serve::Tcp(socket_addr) => { - info!(target: "api", "Server listening on {socket_addr}"); - let listener = std::net::TcpListener::bind(socket_addr)?; - listener.set_nonblocking(true)?; - Ok(Listener::Tcp(TcpListener::from_std(listener)?)) + match self { + Serve::Tcp(socket_addr) => { + info!(target: "api", "Server listening on {socket_addr}"); + let listener = std::net::TcpListener::bind(socket_addr)?; + listener.set_nonblocking(true)?; + Ok(Listener::Tcp(TcpListener::from_std(listener)?)) + } + Serve::Unix { path, permission } => { + info!(target: "api", + "Server listening on unxis domain socket {path} {:o}", + permission.mode() + ); + if let Err(e) = std::fs::remove_file(path) { + let kind = e.kind(); + if kind != ErrorKind::NotFound { + return Err(e); + } } - Serve::Unix { path, permission } => { + let listener = std::os::unix::net::UnixListener::bind(path)?; + std::fs::set_permissions(path, permission.clone())?; + listener.set_nonblocking(true)?; + Ok(Listener::Unix(UnixListener::from_std(listener)?)) + } + Serve::Systemd => { + let mut listenfd = ListenFd::from_env(); + if let Ok(Some(unix)) = listenfd.take_unix_listener(0) { info!(target: "api", - "Server listening on unxis domain socket {path} {:o}", - permission.mode() + "Server listening on activated unix socket {:?}", + unix.local_addr()? ); - if let Err(e) = std::fs::remove_file(path) { - let kind = e.kind(); - if kind != ErrorKind::NotFound { - return Err(e); - } - } - let listener = std::os::unix::net::UnixListener::bind(path)?; - std::fs::set_permissions(path, permission.clone())?; - listener.set_nonblocking(true)?; - Ok(Listener::Unix(UnixListener::from_std(listener)?)) + unix.set_nonblocking(true)?; + Ok(Listener::Unix(UnixListener::from_std(unix)?)) + } else if let Ok(Some(tcp)) = listenfd.take_tcp_listener(0) { + info!(target: "api", + "Server listening on activated TCP socket {:?}", + tcp.local_addr()? + ); + tcp.set_nonblocking(true)?; + Ok(Listener::Tcp(TcpListener::from_std(tcp)?)) + } else { + Err(std::io::Error::other("Missing systemd activated socket")) } } } diff --git a/debian/etc/taler-cyclos/conf.d/cyclos-htppd.conf b/debian/etc/taler-cyclos/conf.d/cyclos-htppd.conf @@ -1,9 +0,0 @@ -# Configuration the cyclos adapter worker REST API. - -[cyclos-httpd-wire-gateway-api] -# ENABLED = YES -@inline-secret@ cyclos-httpd-wire-gateway-api ../secrets/cyclos-httpd.secret.conf - -[cyclos-httpd-revenue-api] -# ENABLED = YES -@inline-secret@ cyclos-httpd-revenue-api ../secrets/cyclos-httpd.secret.conf diff --git a/debian/etc/taler-cyclos/conf.d/cyclos-httpd.conf b/debian/etc/taler-cyclos/conf.d/cyclos-httpd.conf @@ -0,0 +1,12 @@ +# Configuration the cyclos adapter worker REST API. + +[cyclos-httpd] +SERVE = systemd + +[cyclos-httpd-wire-gateway-api] +# ENABLED = YES +@inline-secret@ cyclos-httpd-wire-gateway-api ../secrets/cyclos-httpd.secret.conf + +[cyclos-httpd-revenue-api] +# ENABLED = YES +@inline-secret@ cyclos-httpd-revenue-api ../secrets/cyclos-httpd.secret.conf diff --git a/debian/etc/taler-magnet-bank/conf.d/magnet-bank-httpd.conf b/debian/etc/taler-magnet-bank/conf.d/magnet-bank-httpd.conf @@ -1,5 +1,8 @@ # Configuration the magnet bank adapter worker REST API. +[magnet-bank-httpd] +SERVE = systemd + [magnet-bank-httpd-wire-gateway-api] # ENABLED = YES @inline-secret@ magnet-bank-httpd-wire-gateway-api ../secrets/magnet-bank-httpd.secret.conf