landing-stats: make collector multi-stack reusable
This commit is contained in:
parent
e1cc6d7141
commit
b6c3225e97
7 changed files with 291 additions and 58 deletions
|
|
@ -1,35 +1,41 @@
|
|||
#!/usr/bin/env bash
|
||||
# Install central landing-stats collector as hernani user systemd timer.
|
||||
# Install generic landing-stats collector as user systemd timer.
|
||||
#
|
||||
# On koopa:
|
||||
# GOA / koopa (default):
|
||||
# cd ~/src/koopa/koopa-admin-log
|
||||
# ./scripts/taler-landing/install-landing-stats-host.sh
|
||||
# systemctl --user start taler-landing-stats.service # one-shot now
|
||||
# systemctl --user status taler-landing-stats.timer
|
||||
#
|
||||
# Requires: linger enabled for hernani (loginctl enable-linger hernani)
|
||||
# so the timer runs without an interactive login.
|
||||
# Stage TESTPAYSAN (stagepaysan on francpaysan host):
|
||||
# STACK_PROFILE=stage-testpaysan ./scripts/taler-landing/install-landing-stats-host.sh
|
||||
# # or from francpaysan-admin-log: ./scripts/stagepaysan/install-landing-stats.sh
|
||||
#
|
||||
# Optional: STACK_ENV_FILE=/path/to/profile.env
|
||||
# Requires linger: sudo loginctl enable-linger $USER
|
||||
set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
ADMIN_LOG="${ADMIN_LOG:-$ROOT}"
|
||||
SRC="$ADMIN_LOG/scripts/taler-landing"
|
||||
UNIT_SRC="$ADMIN_LOG/configs/systemd/user"
|
||||
PROFILE="${STACK_PROFILE:-goa}"
|
||||
|
||||
BIN_DST="${HOME}/.local/bin"
|
||||
LIB_DST="${HOME}/.local/lib/taler-landing"
|
||||
UNIT_DST="${HOME}/.config/systemd/user"
|
||||
STATE_DST="${HOME}/.local/state/taler-landing-stats"
|
||||
CFG_DST="${HOME}/.config/taler-landing"
|
||||
|
||||
mkdir -p "$BIN_DST" "$LIB_DST" "$UNIT_DST" "$STATE_DST"
|
||||
mkdir -p "$BIN_DST" "$LIB_DST" "$UNIT_DST" "$STATE_DST" "$CFG_DST"
|
||||
|
||||
install -m 0755 "$SRC/collect-landing-stats.sh" "$BIN_DST/collect-landing-stats.sh"
|
||||
install -m 0755 "$SRC/collect_bank_stats.py" "$LIB_DST/collect_bank_stats.py"
|
||||
install -m 0755 "$SRC/enrich_stats_alt.py" "$LIB_DST/enrich_stats_alt.py"
|
||||
install -m 0755 "$SRC/merge_resources.py" "$LIB_DST/merge_resources.py"
|
||||
install -m 0755 "$SRC/collect_container_resources.sh" "$LIB_DST/collect_container_resources.sh"
|
||||
install -m 0755 "$SRC/test-landing-stats.sh" "$BIN_DST/test-landing-stats.sh" 2>/dev/null || \
|
||||
install -m 0755 "$SRC/test-landing-stats.sh" "$LIB_DST/test-landing-stats.sh"
|
||||
if [ -f "$SRC/test-landing-stats.sh" ]; then
|
||||
install -m 0755 "$SRC/test-landing-stats.sh" "$BIN_DST/test-landing-stats.sh" 2>/dev/null || \
|
||||
install -m 0755 "$SRC/test-landing-stats.sh" "$LIB_DST/test-landing-stats.sh"
|
||||
fi
|
||||
install -m 0644 "$SRC/goa_amounts.py" "$LIB_DST/goa_amounts.py"
|
||||
# mem-snapshot helper lives in taler-shared (copied into containers at collect time)
|
||||
if [ -f "$ADMIN_LOG/scripts/taler-shared/mem-snapshot.sh" ]; then
|
||||
|
|
@ -37,18 +43,34 @@ if [ -f "$ADMIN_LOG/scripts/taler-shared/mem-snapshot.sh" ]; then
|
|||
"$LIB_DST/mem-snapshot.sh"
|
||||
fi
|
||||
|
||||
# Wrapper always uses installed lib next to itself when LIB discovery works;
|
||||
# also point ADMIN_LOG for in-container script refresh.
|
||||
# Stack profile → ~/.config/taler-landing/stack.env (sourced by collector)
|
||||
if [ -n "${STACK_ENV_FILE:-}" ] && [ -f "${STACK_ENV_FILE}" ]; then
|
||||
install -m 0644 "${STACK_ENV_FILE}" "$CFG_DST/stack.env"
|
||||
elif [ -f "$SRC/profiles/${PROFILE}.env" ]; then
|
||||
install -m 0644 "$SRC/profiles/${PROFILE}.env" "$CFG_DST/stack.env"
|
||||
else
|
||||
echo "WARN: no profile ${PROFILE}.env — collector uses built-in GOA defaults" >&2
|
||||
fi
|
||||
|
||||
install -m 0644 "$UNIT_SRC/taler-landing-stats.service" "$UNIT_DST/"
|
||||
install -m 0644 "$UNIT_SRC/taler-landing-stats.timer" "$UNIT_DST/"
|
||||
|
||||
# Rewrite ExecStart to installed binary if unit uses %h path — units already do.
|
||||
# Point unit EnvironmentFile at stack profile
|
||||
if grep -q '^EnvironmentFile=' "$UNIT_DST/taler-landing-stats.service" 2>/dev/null; then
|
||||
:
|
||||
else
|
||||
# inject after [Service]
|
||||
sed -i '/^\[Service\]/a EnvironmentFile=-%h/.config/taler-landing/stack.env' \
|
||||
"$UNIT_DST/taler-landing-stats.service"
|
||||
fi
|
||||
|
||||
systemctl --user daemon-reload
|
||||
systemctl --user enable --now taler-landing-stats.timer
|
||||
|
||||
echo "Installed (user=$(id -un)):"
|
||||
echo "Installed (user=$(id -un) profile=${PROFILE}):"
|
||||
echo " $BIN_DST/collect-landing-stats.sh"
|
||||
echo " $LIB_DST/{collect_bank_stats,enrich_stats_alt,goa_amounts}.py"
|
||||
echo " $CFG_DST/stack.env"
|
||||
echo " $UNIT_DST/taler-landing-stats.{service,timer} (timer enabled)"
|
||||
echo " logs: $STATE_DST/"
|
||||
echo
|
||||
|
|
@ -61,8 +83,6 @@ echo "Run once now:"
|
|||
echo " systemctl --user start taler-landing-stats.service"
|
||||
echo " journalctl --user -u taler-landing-stats.service -n 40 --no-pager"
|
||||
echo
|
||||
echo "Optional secrets (if not readable via podman exec bank /root/…):"
|
||||
echo " mkdir -p ~/.config/taler-landing"
|
||||
echo " cp …/bank-admin-password.txt ~/.config/taler-landing/"
|
||||
echo " cp …/bank-explorer-password.txt ~/.config/taler-landing/"
|
||||
echo " chmod 600 ~/.config/taler-landing/*"
|
||||
echo "Secrets (if not via podman exec bank):"
|
||||
echo " mkdir -p ~/.config/taler-landing && chmod 700 ~/.config/taler-landing"
|
||||
echo " # bank-admin-password.txt bank-explorer-password.txt"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue