taler-monitoring/host-agent/install-host-agent.sh
Hernâni Marques 2451c66173
fix 1.23.7: FP stage host-agent install and tip parity with GOA
Ship fp-stage systemd units; install-host-agent.sh --fp-stage for stagepaysan
(disables GOA timers on FP host). Env example enforces SUITE_REQUIRE_REMOTE_TIP.
2026-07-22 03:54:09 +02:00

237 lines
11 KiB
Bash
Executable file

#!/usr/bin/env bash
# install-host-agent.sh — install user systemd mon units
#
# # GOA / koopa as hernani (default):
# ~/src/taler-monitoring/host-agent/install-host-agent.sh
# # FrancPaysan stage as stagepaysan:
# ~/src/taler-monitoring/host-agent/install-host-agent.sh --fp-stage
# # from laptop:
# ./install-host-agent.sh --remote $DEPLOY_SSH
# ./install-host-agent.sh --remote $DEPLOY_SSH --fp-stage
#
# Suite tree is ONLY ~/src/taler-monitoring (standalone repo). No koopa-admin-log.
# Both stacks share run-host-report.sh → update-suite tip enforcement + per-dir publish.
#
set -euo pipefail
ROOT=$(cd "$(dirname "$0")" && pwd)
REMOTE=""
STACK="${HOST_AGENT_STACK:-goa}"
while [ $# -gt 0 ]; do
case "$1" in
--remote)
REMOTE="${2:-${DEPLOY_SSH:-}}"
shift 2
;;
--fp-stage|--fp|--stagepaysan)
STACK=fp-stage
shift
;;
--goa|goa)
STACK=goa
shift
;;
*)
# bare host = remote (legacy)
if [ -z "$REMOTE" ] && [ "$1" != "--remote" ]; then
REMOTE="$1"
fi
shift
;;
esac
done
SUITE_URL="${SUITE_GIT_URL:-https://git.hacktivism.ch/hernani/taler-monitoring.git}"
install_fp_stage() {
local mon home_unit
mon=$(cd "$ROOT/.." && pwd)
if [ -d "$HOME/src/taler-monitoring/.git" ] || [ -d "$HOME/src/taler-monitoring" ]; then
mon="$HOME/src/taler-monitoring"
fi
home_unit="$HOME/.config/systemd/user"
mkdir -p "$home_unit" \
"$HOME/.local/state/taler-monitoring-stage-lfp" \
"$HOME/monitoring-sites-staging" \
"$HOME/.config/taler-monitoring" \
"$HOME/src"
if [ ! -f "$HOME/.config/taler-monitoring/env" ] && [ -f "$ROOT/env/stagepaysan.env.example" ]; then
cp "$ROOT/env/stagepaysan.env.example" "$HOME/.config/taler-monitoring/env"
echo "created ~/.config/taler-monitoring/env from stagepaysan.env.example"
fi
# Ensure tip-enforcement knobs present (idempotent append if missing)
if [ -f "$HOME/.config/taler-monitoring/env" ]; then
grep -q '^SUITE_UPDATE_MODE=' "$HOME/.config/taler-monitoring/env" 2>/dev/null \
|| echo 'SUITE_UPDATE_MODE=reset' >>"$HOME/.config/taler-monitoring/env"
grep -q '^SUITE_UPDATE_STRICT=' "$HOME/.config/taler-monitoring/env" 2>/dev/null \
|| echo 'SUITE_UPDATE_STRICT=1' >>"$HOME/.config/taler-monitoring/env"
grep -q '^SUITE_REQUIRE_REMOTE_TIP=' "$HOME/.config/taler-monitoring/env" 2>/dev/null \
|| echo 'SUITE_REQUIRE_REMOTE_TIP=1' >>"$HOME/.config/taler-monitoring/env"
fi
if [ ! -d "$HOME/src/taler-monitoring/.git" ]; then
echo "clone $SUITE_URL$HOME/src/taler-monitoring"
git clone "$SUITE_URL" "$HOME/src/taler-monitoring" \
|| echo "WARN: clone failed — using tree at $mon if present"
fi
mon="$HOME/src/taler-monitoring"
ln -sfn "$mon" "$HOME/taler-monitoring" 2>/dev/null || true
(
cd "$mon"
git fetch --tags --force --prune origin 2>/dev/null || true
git checkout -B main origin/main 2>/dev/null || git checkout main 2>/dev/null || true
git reset --hard origin/main 2>/dev/null || true
)
chmod +x "$mon"/taler-monitoring.sh "$mon"/check_*.sh 2>/dev/null || true
chmod +x "$mon/host-agent"/*.sh 2>/dev/null || true
chmod +x "$mon/site-gen"/*.sh "$mon/site-gen/console_to_html.py" 2>/dev/null || true
install -m 644 "$ROOT/taler-monitoring-fp-stage.service" "$home_unit/"
install -m 644 "$ROOT/taler-monitoring-fp-stage.timer" "$home_unit/"
chmod +x "$ROOT/run-fp-stage-monitoring.sh" 2>/dev/null || true
# FP host must not run GOA timers (would write GOA mon dirs / wrong inventory)
for u in taler-monitoring-hacktivism taler-monitoring-surface \
taler-monitoring-aptdeploy taler-monitoring-max-ladder \
taler-monitoring-mail taler-monitoring-mattermost; do
systemctl --user disable --now "${u}.timer" 2>/dev/null || true
systemctl --user disable --now "${u}.path" 2>/dev/null || true
systemctl --user stop "${u}.service" 2>/dev/null || true
rm -f "$home_unit/${u}.service" "$home_unit/${u}.timer" "$home_unit/${u}.path" 2>/dev/null || true
done
systemctl --user daemon-reload
systemctl --user enable --now taler-monitoring-fp-stage.timer
systemctl --user start --no-block taler-monitoring-fp-stage.service || true
echo "--- FP stage status ---"
systemctl --user status taler-monitoring-fp-stage.timer --no-pager -l | head -12 || true
systemctl --user list-timers --all | grep taler-monitoring || true
echo "OK host-agent FP stage:"
echo " · fp-stage 4h → /monitoring on stage.{bank,exchange,monnaie}.lefrancpaysan.ch"
echo " · suite tip: $mon (SUITE_REQUIRE_REMOTE_TIP=1 via run-host-report)"
echo "manual: systemctl --user start taler-monitoring-fp-stage.service"
}
install_local() {
local mon home_unit
mon=$(cd "$ROOT/.." && pwd)
if [ -d "$HOME/src/taler-monitoring/.git" ] || [ -d "$HOME/src/taler-monitoring" ]; then
mon="$HOME/src/taler-monitoring"
fi
home_unit="$HOME/.config/systemd/user"
mkdir -p "$home_unit" \
"$HOME/.local/state/taler-hacktivism-monitoring" \
"$HOME/monitoring-sites-staging" \
"$HOME/.config/taler-monitoring" \
"$HOME/src"
# Local env (never in git) — create from example if missing
if [ ! -f "$HOME/.config/taler-monitoring/env" ] && [ -f "$ROOT/env.example" ]; then
cp "$ROOT/env.example" "$HOME/.config/taler-monitoring/env"
echo "created ~/.config/taler-monitoring/env"
fi
# Ensure suite git clone at canonical path
if [ ! -d "$HOME/src/taler-monitoring/.git" ]; then
if [ -d "$mon/.git" ] && [ "$mon" != "$HOME/src/taler-monitoring" ]; then
mkdir -p "$HOME/src"
ln -sfn "$mon" "$HOME/src/taler-monitoring"
echo "symlink $HOME/src/taler-monitoring → $mon"
else
echo "clone $SUITE_URL$HOME/src/taler-monitoring"
git clone "$SUITE_URL" "$HOME/src/taler-monitoring" \
|| echo "WARN: clone failed (auth/network) — using tree at $mon if present"
fi
fi
mon="$HOME/src/taler-monitoring"
# Convenience link (update-suite.sh also creates this)
ln -sfn "$mon" "$HOME/taler-monitoring" 2>/dev/null || true
# Ensure suite is executable
chmod +x "$mon"/taler-monitoring.sh "$mon"/check_*.sh 2>/dev/null || true
chmod +x "$mon/host-agent"/*.sh 2>/dev/null || true
chmod +x "$mon/site-gen"/*.sh "$mon/site-gen/console_to_html.py" 2>/dev/null || true
install -m 644 "$ROOT/taler-monitoring-hacktivism.service" "$home_unit/"
install -m 644 "$ROOT/taler-monitoring-hacktivism.path" "$home_unit/"
install -m 644 "$ROOT/taler-monitoring-hacktivism.timer" "$home_unit/"
install -m 644 "$ROOT/taler-monitoring-surface.service" "$home_unit/"
install -m 644 "$ROOT/taler-monitoring-surface.timer" "$home_unit/"
# optional aptdeploy (not a public mon page layout — v1.8.0 simplified overview)
install -m 644 "$ROOT/taler-monitoring-aptdeploy.service" "$home_unit/"
install -m 644 "$ROOT/taler-monitoring-aptdeploy.timer" "$home_unit/"
# GOA max-search amount ladder page (daily only — no classic /monitoring-ladder)
install -m 644 "$ROOT/taler-monitoring-max-ladder.service" "$home_unit/"
install -m 644 "$ROOT/taler-monitoring-max-ladder.timer" "$home_unit/"
chmod +x "$ROOT/run-max-ladder-monitoring.sh" 2>/dev/null || true
systemctl --user daemon-reload
systemctl --user enable --now taler-monitoring-hacktivism.path
systemctl --user enable --now taler-monitoring-hacktivism.timer
systemctl --user enable --now taler-monitoring-surface.timer
systemctl --user enable --now taler-monitoring-aptdeploy.timer
systemctl --user enable --now taler-monitoring-max-ladder.timer
# drop classic ladder mon page if previously installed
systemctl --user disable --now taler-monitoring-ladder.timer 2>/dev/null || true
systemctl --user stop taler-monitoring-ladder.service 2>/dev/null || true
rm -f "$home_unit/taler-monitoring-ladder.service" \
"$home_unit/taler-monitoring-ladder.timer" 2>/dev/null || true
# Remove leftover mail/mattermost units if present (moved to meta/deprecated/)
systemctl --user disable --now taler-monitoring-mattermost.timer 2>/dev/null || true
systemctl --user disable --now taler-monitoring-mail.timer 2>/dev/null || true
rm -f "$home_unit/taler-monitoring-mattermost.service" \
"$home_unit/taler-monitoring-mattermost.timer" \
"$home_unit/taler-monitoring-mail.service" \
"$home_unit/taler-monitoring-mail.timer" 2>/dev/null || true
systemctl --user daemon-reload 2>/dev/null || true
# initial stamp so path exists
"$ROOT/touch-software-stamp.sh"
# oneshot jobs: --no-block so install does not wait hours
systemctl --user start --no-block taler-monitoring-hacktivism.service || true
systemctl --user start --no-block taler-monitoring-surface.service || true
systemctl --user start --no-block taler-monitoring-aptdeploy.service || true
# first max-ladder round immediately (daily thereafter)
systemctl --user start --no-block taler-monitoring-max-ladder.service || true
echo "--- status ---"
systemctl --user status taler-monitoring-hacktivism.path --no-pager -l | head -15
systemctl --user status taler-monitoring-hacktivism.timer --no-pager -l | head -12
systemctl --user status taler-monitoring-surface.timer --no-pager -l | head -12
systemctl --user status taler-monitoring-aptdeploy.timer --no-pager -l | head -12
systemctl --user status taler-monitoring-max-ladder.timer --no-pager -l | head -12
systemctl --user list-timers --all | grep taler-monitoring || true
echo "OK host-agent:"
echo " · hacktivism 4h → /monitoring on bank/exchange/taler (landing stacks)"
echo " · max-ladder daily → /monitoring-max-ladder/ (GOA max-search, bank/exchange/taler)"
echo " · surface 1h → /taler-monitoring-surface* (ecosystem versions/software)"
echo " · aptdeploy 4h (optional tests)"
echo " · no classic /monitoring-ladder page"
echo " · mail/mattermost: not installed (meta/deprecated/; content in surface)"
echo "suite: $mon"
echo "manual max-ladder: systemctl --user start taler-monitoring-max-ladder.service"
echo "after upgrades: $ROOT/touch-software-stamp.sh"
}
if [ -n "$REMOTE" ] && [ "$REMOTE" != "--remote" ]; then
echo "install on $REMOTE (stack=$STACK) …"
# ROOT = …/taler-monitoring/host-agent → suite root is parent
rsync -az --delete \
--exclude secrets.env \
--exclude 'android-test/artifacts' \
--exclude '.git' \
"$ROOT/../" \
"${REMOTE}:src/taler-monitoring/"
if [ "$STACK" = "fp-stage" ]; then
ssh -o BatchMode=yes "$REMOTE" \
'bash $HOME/src/taler-monitoring/host-agent/install-host-agent.sh --fp-stage'
else
ssh -o BatchMode=yes "$REMOTE" \
'bash $HOME/src/taler-monitoring/host-agent/install-host-agent.sh'
fi
else
if [ "$STACK" = "fp-stage" ]; then
install_fp_stage
else
install_local
fi
fi