#!/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" <> "$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" "$@"