taler-monitoring/host-agent/install-host-agent.sh
Hernâni Marques c1a3cba28b
fix 1.23.1: only /monitoring-max-ladder for GOA (drop classic ladder page)
Hacktivism mon page is max-search only on bank/exchange/taler. Remove
classic /monitoring-ladder units, monpages catalog, and Caddy bare redirs.
2026-07-19 15:05:21 +02:00

129 lines
6.2 KiB
Bash
Executable file

#!/usr/bin/env bash
# install-host-agent.sh — install hernani user systemd units on koopa
#
# # on koopa as hernani:
# ~/src/taler-monitoring/host-agent/install-host-agent.sh
# # or from laptop:
# ./install-host-agent.sh --remote $DEPLOY_SSH
#
# Suite tree is ONLY ~/src/taler-monitoring (standalone repo). No koopa-admin-log.
#
set -euo pipefail
ROOT=$(cd "$(dirname "$0")" && pwd)
REMOTE="${1:-}"
[ "${1:-}" = "--remote" ] && REMOTE="${2:-${DEPLOY_SSH:-}}"
SUITE_URL="${SUITE_GIT_URL:-https://git.hacktivism.ch/hernani/taler-monitoring.git}"
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"
systemctl --user start taler-monitoring-hacktivism.service || true
systemctl --user start taler-monitoring-surface.service || true
systemctl --user start taler-monitoring-aptdeploy.service || true
# first max-ladder round immediately (daily thereafter)
systemctl --user start 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"
# 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/"
ssh -o BatchMode=yes "$REMOTE" \
'bash $HOME/src/taler-monitoring/host-agent/install-host-agent.sh'
else
install_local
fi