Files
taler-merchant-docker-dev-env/merchant/entrypoint.sh
T
2026-10-21 15:21:20 +02:00

69 lines
2.6 KiB
Bash

#!/bin/sh
# Entrypoint for the GNU Taler merchant backend container.
#
# Renders the configuration from environment variables, initializes the
# PostgreSQL database schema, and starts the backend HTTP service plus the
# auxiliary daemons that the systemd taler-merchant.target would normally
# run (see Merchant Backend Operator Manual, section "Launching the backend"):
# https://docs.taler.net/taler-merchant-manual.html#launching-the-backend
set -eu
MAIN_CONFIG="/etc/taler-merchant/taler-merchant.conf"
OVERRIDES="/etc/taler-merchant/merchant-overrides.conf"
MERCHANT_PORT="${TALER_MERCHANT_PORT:-9966}"
MERCHANT_CURRENCY="${TALER_MERCHANT_CURRENCY:-KUDOS}"
DB_CONFIG="${TALER_MERCHANT_DB:-postgres:///taler-merchant}"
# The Debian package runs the backend as a dedicated user.
RUN_USER="$(getent passwd | awk -F: '$1 ~ /^taler-merchant/ {print $1; exit}')"
RUN_USER="${RUN_USER:-taler-merchant-httpd}"
RUN_GROUP="$(id -gn "$RUN_USER")"
# Render the package overrides: service address, currency and database.
cat > "$OVERRIDES" <<EOF
# Generated by the container entrypoint - do not edit.
# Configure via the TALER_MERCHANT_* environment variables instead.
[merchant]
SERVE = tcp
PORT = ${MERCHANT_PORT}
CURRENCY = ${MERCHANT_CURRENCY}
DATABASE = postgres
[merchantdb-postgres]
CONFIG = ${DB_CONFIG}
EOF
# Make sure the shipped main configuration includes the overrides.
if ! grep -q "merchant-overrides.conf" "$MAIN_CONFIG"; then
printf '@INLINE@ %s\n' "$OVERRIDES" >> "$MAIN_CONFIG"
fi
# Initialize the database schema. Safe to re-run: existing databases are
# preserved unless the tool is invoked with -r (which we never do).
# Retries because the postgres container may still be starting up.
echo "Initializing the merchant database schema..."
try=0
until setpriv --reuid="$RUN_USER" --regid="$RUN_GROUP" --init-groups \
taler-merchant-dbinit -c "$MAIN_CONFIG"; do
try=$((try + 1))
if [ "$try" -ge 30 ]; then
echo "ERROR: could not initialize the merchant database" >&2
exit 1
fi
echo " attempt ${try} failed, retrying in 2 s ..."
sleep 2
done
# Start the auxiliary daemons (background; normally systemd units).
for daemon in webhook wirewatch depositcheck exchangekeyupdate reconciliation kyccheck; do
if command -v "taler-merchant-${daemon}" > /dev/null 2>&1; then
setpriv --reuid="$RUN_USER" --regid="$RUN_GROUP" --init-groups \
"taler-merchant-${daemon}" -c "$MAIN_CONFIG" &
fi
done
echo "Starting taler-merchant-httpd on port ${MERCHANT_PORT} ..."
exec setpriv --reuid="$RUN_USER" --regid="$RUN_GROUP" --init-groups \
taler-merchant-httpd -c "$MAIN_CONFIG" "$@"