bank: merchant-model start scripts + configs for taler-bank-hacktivism

This commit is contained in:
Hernâni Marques 2026-07-01 15:58:30 +02:00
parent 50a4add730
commit d6925e3385
No known key found for this signature in database
7 changed files with 470 additions and 0 deletions

View file

@ -0,0 +1,35 @@
# taler-bank scripts
Container: **`taler-bank-hacktivism`** (libeufin-bank, GOA, **no IBAN**).
| File | Container path | User |
|------|----------------|------|
| `start_base_services_for_taler_bank.sh` | `/root/` | **root** |
| `start_bank.sh` | `/usr/local/bin/` | **libeufin-bank** |
| `check_bank-health.sh` | `/usr/local/bin/` | libeufin-bank / any |
| `landing-stats.sh` | `/usr/local/bin/` | root (in container) — writes `/var/www/bank-landing/stats.json` |
| `landing-stats-install.sh` | host only | root/podman — copies + runs + optional cron |
## Usage
```bash
# root in container
./start_base_services_for_taler_bank.sh
# then as libeufin-bank in /usr/local/bin:
./start_bank.sh --restart
```
## Landing stats (inside container)
```bash
# on koopa host — copy + run (writes /var/www/bank-landing/stats.json)
./landing-stats-install.sh
./landing-stats-install.sh --cron # every minute inside container (* * * * *)
./landing-stats-install.sh --run-only
```
Details + JSON schema: `configs/bank-landing/README.md`.
## Config
See `configs/taler-bank/`.

View file

@ -0,0 +1,48 @@
#!/bin/bash
# Health check for manual libeufin-bank (same style as merchant/exchange health).
# Container: taler-hacktivism-bank
CONF=/etc/libeufin/libeufin-bank.conf
PORT=$(grep -E '^\s*PORT\s*=' /etc/libeufin/bank-overrides.conf 2>/dev/null | tail -1 | awk -F= '{gsub(/ /,"",$2); print $2}')
PORT=${PORT:-9012}
green() { echo -e "\e[32m$1\e[0m"; }
red() { echo -e "\e[31m$1\e[0m"; }
yellow() { echo -e "\e[33m$1\e[0m"; }
fail=0
ok() { green "[OK] $1"; }
bad() { red "[FAIL] $1"; fail=1; }
echo "=== Taler Bank (libeufin-bank) Health Check ==="
if pgrep -f 'libeufin-bank serve|MainKt serve|tech.libeufin.bank.MainKt' >/dev/null 2>&1; then
ok "process libeufin-bank serve"
else
bad "process libeufin-bank serve is NOT running"
fi
if curl -sf -m 3 "http://127.0.0.1:${PORT}/config" >/dev/null 2>&1; then
ok "HTTP /config on 127.0.0.1:${PORT}"
else
bad "no HTTP response on 127.0.0.1:${PORT}/config"
fi
if curl -sf -m 3 "http://127.0.0.1:${PORT}/taler-integration/config" >/dev/null 2>&1; then
ok "HTTP /taler-integration/config on 127.0.0.1:${PORT}"
else
yellow "[WARN] no HTTP response on /taler-integration/config"
fi
if pg_isready >/dev/null 2>&1; then
ok "postgresql accepting connections"
else
yellow "[WARN] postgresql not ready (or pg_isready missing)"
fi
if [ "$fail" -eq 0 ]; then
green "=== ALL CRITICAL CHECKS PASSED ==="
exit 0
fi
red "=== SOME CHECKS FAILED ==="
exit 1

109
scripts/taler-bank/start_bank.sh Executable file
View file

@ -0,0 +1,109 @@
#!/bin/bash
# Start / restart libeufin-bank serve (manual, no systemd).
# Run as: libeufin-bank
# Same role as start_merchant.sh / start_exchange.sh.
#
# Container: taler-hacktivism-bank
# Prerequisite: /root/start_base_services_for_taler_bank.sh (as root) for postgres.
#
# Usage:
# start_bank.sh
# start_bank.sh --restart | -r
# start_bank.sh --help
set -u
usage() {
cat <<'EOF'
Usage: start_bank.sh [--restart|-r] [--help|-h]
(default) Start libeufin-bank serve if not already running.
--restart Stop live serve process, then start cleanly.
Does not touch postgres (use /root/start_base_services_for_taler_bank.sh).
EOF
}
DO_RESTART=0
for arg in "$@"; do
case "$arg" in
--restart|-r) DO_RESTART=1 ;;
--help|-h) usage; exit 0 ;;
*) echo "Unknown option: $arg" >&2; usage >&2; exit 2 ;;
esac
done
if [ "$(id -un)" != "libeufin-bank" ]; then
echo "This script must be run as user libeufin-bank" >&2
exit 1
fi
CONF=/etc/libeufin/libeufin-bank.conf
LOG_DIR=/var/log/libeufin-bank
PORT=$(grep -E '^\s*PORT\s*=' /etc/libeufin/bank-overrides.conf 2>/dev/null | tail -1 | awk -F= '{gsub(/ /,"",$2); print $2}')
PORT=${PORT:-9012}
# Match both wrapper name and the Java MainKt process that actually listens.
list_serve_pids() {
ps -eo pid=,stat=,args= 2>/dev/null | while read -r pid stat args; do
case "$stat" in Z*) continue ;; esac
case "$args" in
*start_bank.sh*) continue ;;
*check_bank-health*) continue ;;
esac
case "$args" in
*libeufin-bank\ serve*|/usr/bin/libeufin-bank\ serve*|*MainKt\ serve*|*tech.libeufin.bank.MainKt*)
echo "$pid"
;;
esac
done | sort -u
}
kill_serve() {
local pids
pids=$(list_serve_pids | tr '\n' ' ')
if [ -z "${pids// }" ]; then
echo "No live libeufin-bank serve to stop."
return 0
fi
echo "Stopping PIDs: $pids"
# shellcheck disable=SC2086
kill -TERM $pids 2>/dev/null || true
sleep 2
local left
left=$(list_serve_pids | tr '\n' ' ')
if [ -n "${left// }" ]; then
echo "SIGKILL remaining: $left"
# shellcheck disable=SC2086
kill -KILL $left 2>/dev/null || true
sleep 1
fi
echo "libeufin-bank serve stopped."
}
if [ "$DO_RESTART" -eq 1 ]; then
echo "=== restart: kill libeufin-bank serve ==="
kill_serve
fi
echo "Start libeufin-bank serve (port $PORT):"
LOG_FILE="$LOG_DIR/libeufin-bank-$(date +%Y-%m-%d).log"
mkdir -p "$LOG_DIR"
touch "$LOG_FILE" 2>/dev/null || true
if [ "$DO_RESTART" -eq 0 ] && [ -n "$(list_serve_pids)" ]; then
echo "libeufin-bank serve already running"
else
nohup libeufin-bank serve -c "$CONF" >>"$LOG_FILE" 2>&1 &
disown 2>/dev/null || true
sleep 2
fi
echo "Live processes:"
ps -eo pid,stat,args 2>/dev/null | grep -E 'libeufin-bank serve|MainKt serve' | grep -v grep | grep -v ' Z ' || true
if [ -x /usr/local/bin/check_bank-health.sh ]; then
/usr/local/bin/check_bank-health.sh || exit 1
elif [ -x ./check_bank-health.sh ]; then
./check_bank-health.sh || exit 1
fi
exit 0

View file

@ -0,0 +1,148 @@
#!/bin/bash
# Root: base services for manual libeufin-bank (like merchant/exchange start_base).
# Then interactive shell as libeufin-bank → run start_bank.sh there.
#
# Container: taler-hacktivism-bank
#
# Usage:
# /root/start_base_services_for_taler_bank.sh
# /root/start_base_services_for_taler_bank.sh --no-shell
# /root/start_base_services_for_taler_bank.sh --no-shell --start-bank
# /root/start_base_services_for_taler_bank.sh --no-shell --start-bank --restart
set -e
CONF=/etc/libeufin/libeufin-bank.conf
LOG_DIR=/var/log/libeufin-bank
PWD_BIN=/usr/local/bin
BANK_STARTER=start_bank.sh
BANK_USER=libeufin-bank
if [ "$(id -u)" -ne 0 ]; then
echo "Run as root" >&2
exit 1
fi
NO_SHELL=0
START_BANK=0
BANK_RESTART=0
for arg in "$@"; do
case "$arg" in
--no-shell|-n) NO_SHELL=1 ;;
--start-bank) START_BANK=1; NO_SHELL=1 ;;
--restart|-r) BANK_RESTART=1 ;;
--help|-h)
cat <<'EOF'
Usage: start_base_services_for_taler_bank.sh [options]
(default) Start postgres + dirs, then interactive shell as libeufin-bank
--no-shell Start base services only, do not open a shell
--start-bank After base services, run /usr/local/bin/start_bank.sh as libeufin-bank
(implies --no-shell)
--restart With --start-bank: pass --restart to start_bank.sh
EOF
exit 0
;;
*)
echo "Unknown option: $arg" >&2
exit 2
;;
esac
done
# --- Debian postgresql defaults (pg_createcluster layout) ---
ensure_postgresql() {
echo " Debian perms on /etc/postgresql + data/log/run..."
if [ -d /etc/postgresql ]; then
chown -R root:postgres /etc/postgresql
find /etc/postgresql -type d -exec chmod 755 {} \;
find /etc/postgresql -type f -name '*.conf' -exec chmod 640 {} \;
fi
chown -R postgres:postgres /var/lib/postgresql /var/log/postgresql 2>/dev/null || true
mkdir -p /var/run/postgresql
chown postgres:postgres /var/run/postgresql
chmod 2775 /var/run/postgresql 2>/dev/null || chmod 775 /var/run/postgresql
# Snakeoil TLS key: postgres fails if it cannot read the key (common in rootless images).
# Prefer fixing perms; if still broken, force ssl=off for local-only DB.
if [ -f /etc/ssl/private/ssl-cert-snakeoil.key ]; then
chown root:ssl-cert /etc/ssl/private/ssl-cert-snakeoil.key 2>/dev/null || true
chmod 640 /etc/ssl/private/ssl-cert-snakeoil.key 2>/dev/null || true
fi
for pgconf in /etc/postgresql/*/main/postgresql.conf; do
[ -f "$pgconf" ] || continue
if grep -qE '^\s*ssl\s*=' "$pgconf"; then
sed -i 's/^\s*ssl\s*=.*/ssl = off/' "$pgconf"
else
echo "ssl = off" >>"$pgconf"
fi
done
if pg_isready -q 2>/dev/null; then
echo " already accepting connections"
pg_isready || true
return 0
fi
rm -f /var/run/postgresql/.s.PGSQL.*.lock 2>/dev/null || true
if ! pgrep -u postgres -x postgres >/dev/null 2>&1; then
rm -f /var/lib/postgresql/*/main/postmaster.pid 2>/dev/null || true
fi
if command -v pg_ctlcluster >/dev/null 2>&1 && command -v pg_lsclusters >/dev/null 2>&1; then
while read -r ver name _rest; do
[ -n "$ver" ] || continue
echo " pg_ctlcluster $ver $name start"
pg_ctlcluster "$ver" "$name" start 2>/dev/null || true
done < <(pg_lsclusters --no-header 2>/dev/null || true)
fi
if ! pg_isready -q 2>/dev/null; then
if [ -x /etc/init.d/postgresql ]; then
/etc/init.d/postgresql start || true
else
service postgresql start || true
fi
fi
sleep 1
pg_isready || true
}
echo "Create log + data dirs... giving permission to ${BANK_USER}:"
mkdir -p "$LOG_DIR" /var/lib/libeufin-bank
chown "${BANK_USER}:${BANK_USER}" "$LOG_DIR" /var/lib/libeufin-bank
chmod 755 "$LOG_DIR" /var/lib/libeufin-bank
echo "Start base services needed for GOA Exploration Bank."
echo ""
echo "1. postgresql:"
ensure_postgresql
# ensure role + DB (postgres:///libeufin) — Debian createuser/createdb as postgres
su -s /bin/bash postgres -c "psql -tc \"SELECT 1 FROM pg_roles WHERE rolname='libeufin-bank'\" | grep -q 1 || createuser -s libeufin-bank" || true
su -s /bin/bash postgres -c "psql -tc \"SELECT 1 FROM pg_database WHERE datname='libeufin'\" | grep -q 1 || createdb -O libeufin-bank libeufin" || true
pg_isready || true
if [ "$START_BANK" -eq 1 ]; then
echo ""
echo "2. start_bank.sh as ${BANK_USER}:"
if [ ! -x "$PWD_BIN/$BANK_STARTER" ]; then
echo "missing $PWD_BIN/$BANK_STARTER" >&2
exit 1
fi
if [ "$BANK_RESTART" -eq 1 ]; then
runuser -u "$BANK_USER" -- "$PWD_BIN/$BANK_STARTER" --restart
else
runuser -u "$BANK_USER" -- "$PWD_BIN/$BANK_STARTER"
fi
exit $?
fi
if [ "$NO_SHELL" -eq 1 ]; then
echo "Base services started (--no-shell). Next: runuser -u ${BANK_USER} -- $PWD_BIN/$BANK_STARTER [--restart]"
exit 0
fi
echo "2. Switching now to user ${BANK_USER}, in $PWD_BIN; find executable $BANK_STARTER there!"
echo ""
cd "$PWD_BIN"
# util-linux: -u and -s are mutually exclusive (same as exchange/merchant)
exec runuser -u "$BANK_USER" -- bash