88 lines
3.7 KiB
Bash
Executable file
88 lines
3.7 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Install generic landing-stats collector as user systemd timer.
|
|
#
|
|
# GOA / koopa (default):
|
|
# cd ~/src/koopa/koopa-admin-log
|
|
# ./scripts/taler-landing/install-landing-stats-host.sh
|
|
#
|
|
# 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" "$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"
|
|
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
|
|
install -m 0644 "$ADMIN_LOG/scripts/taler-shared/mem-snapshot.sh" \
|
|
"$LIB_DST/mem-snapshot.sh"
|
|
fi
|
|
|
|
# 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/"
|
|
|
|
# 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) 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
|
|
if ! loginctl show-user "$(id -un)" -p Linger 2>/dev/null | grep -q 'Linger=yes'; then
|
|
echo "NOTE: enable linger so the timer survives logout:"
|
|
echo " sudo loginctl enable-linger $(id -un)"
|
|
echo
|
|
fi
|
|
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 "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"
|