ops: GOA vanilla landings stats wdGet + collect greening
This commit is contained in:
parent
0d881cd726
commit
337d253691
24 changed files with 1074 additions and 107 deletions
|
|
@ -2,7 +2,8 @@
|
|||
# Run INSIDE taler-hacktivism-exchange-ansible.
|
||||
# Writes /var/www/exchange-landing/stats.json
|
||||
#
|
||||
# Data lives in Postgres DB taler-exchange, schema exchange.*
|
||||
# Data lives in Postgres (DB name varies: vanilla regio-ng uses "exchange";
|
||||
# older hacktivism images use "taler-exchange"). Schema is exchange.*.
|
||||
# (reserves, reserves_in, known_coins, withdraw, denominations, …)
|
||||
#
|
||||
# IMPORTANT: never use psql -F$'\t' -v ON_ERROR_STOP=1
|
||||
|
|
@ -16,7 +17,38 @@ LANDING_DIR="${LANDING_DIR:-/var/www/exchange-landing}"
|
|||
OUT="$LANDING_DIR/stats.json"
|
||||
RUN="$LANDING_DIR/stats-run.json"
|
||||
TMP="${OUT}.tmp.$$"
|
||||
DB="${EXCHANGE_DB:-taler-exchange}"
|
||||
# Resolve DB: EXCHANGE_DB env → CONFIG=postgres:///NAME in secret conf → fallbacks
|
||||
_resolve_exchange_db() {
|
||||
if [ -n "${EXCHANGE_DB:-}" ]; then
|
||||
printf '%s' "$EXCHANGE_DB"
|
||||
return
|
||||
fi
|
||||
local conf c name
|
||||
for conf in \
|
||||
/etc/taler-exchange/secrets/exchange-db.secret.conf \
|
||||
/etc/taler/secrets/exchange-db.secret.conf; do
|
||||
if [ -r "$conf" ]; then
|
||||
c=$(grep -E '^[[:space:]]*CONFIG[[:space:]]*=' "$conf" | head -1 | sed 's/^[^=]*=[[:space:]]*//')
|
||||
# postgres:///dbname or postgres://user@/dbname
|
||||
name=$(printf '%s' "$c" | sed -n 's#.*postgres://[^/]*/\([^?]*\).*#\1#p')
|
||||
if [ -n "$name" ]; then
|
||||
printf '%s' "$name"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
done
|
||||
for name in exchange taler-exchange; do
|
||||
if [ -d "/var/lib/postgresql" ] || command -v psql >/dev/null 2>&1; then
|
||||
if runuser -u postgres -- psql -d "$name" -At -c 'SELECT 1' >/dev/null 2>&1 \
|
||||
|| su -s /bin/bash postgres -c "psql -d $name -At -c 'SELECT 1'" >/dev/null 2>&1; then
|
||||
printf '%s' "$name"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
done
|
||||
printf '%s' "taler-exchange"
|
||||
}
|
||||
DB="$(_resolve_exchange_db)"
|
||||
BASE_URL="${EXCHANGE_BASE_URL:-https://exchange.hacktivism.ch}"
|
||||
ERRLOG="${LANDING_STATS_ERRLOG:-/var/log/landing-stats-exchange.err}"
|
||||
mkdir -p "$LANDING_DIR"
|
||||
|
|
@ -253,7 +285,7 @@ cat >"$TMP" <<EOF
|
|||
{
|
||||
"ok": true,
|
||||
"source": "exchange-db",
|
||||
"schema": "exchange.* @ taler-exchange",
|
||||
"schema": "exchange.* @ ${DB}",
|
||||
"focus": "coins",
|
||||
"timezone": $(json_str "$TZ"),
|
||||
"generated_at": $(json_str "$GEN"),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue