#!/bin/sh # Trouve-KA — installation de la robustesse sur un node (rôle + LaunchDaemons) # Author: Simon-Pierre Boucher # Contact: contact@spboucher.ai # # Usage : SUDO_PW=... sh install-node.sh # Idempotent. Installe : # - ~/.trouveka-role # - io.trouveka.boot (RunAtLoad : boot.sh au démarrage du node) # - hub : + io.trouveka.watchdog (2 min) + backup-pg (03:30) + pull (04:40) # - search : + backup-os (04:00) + pull (04:30) set -eu ROLE="${1:?role requis: hub|search|embed|crawler}" USER_NAME=$(whoami) HOME_DIR="$HOME" OPS="$HOME_DIR/trouve-ka/scripts/ops" echo "$ROLE" > "$HOME_DIR/.trouveka-role" sudo_cmd() { echo "${SUDO_PW:?SUDO_PW requis}" | sudo -S "$@" 2>/dev/null; } install_daemon() { # $1=label $2=program-args-xml $3=extra-xml PLIST="/tmp/io.trouveka.$1.plist" cat > "$PLIST" < Labelio.trouveka.$1 ProgramArguments/bin/sh$2 UserName$USER_NAME StandardErrorPath$HOME_DIR/trouveka-launchd.log StandardOutPath$HOME_DIR/trouveka-launchd.log $3 EOF sudo_cmd cp "$PLIST" "/Library/LaunchDaemons/io.trouveka.$1.plist" sudo_cmd launchctl bootout "system/io.trouveka.$1" 2>/dev/null || true sudo_cmd launchctl bootstrap system "/Library/LaunchDaemons/io.trouveka.$1.plist" echo "✓ daemon io.trouveka.$1" } install_daemon boot "$OPS/boot.sh" "RunAtLoad" case "$ROLE" in hub) install_daemon watchdog "$OPS/watchdog.sh" "StartInterval120" install_daemon backup-pg "$OPS/backup-pg.sh" "StartCalendarIntervalHour3Minute30" install_daemon pull "$OPS/pull-backups.sh" "StartCalendarIntervalHour4Minute40" ;; search) install_daemon backup-os "$OPS/backup-os.sh" "StartCalendarIntervalHour4Minute0" install_daemon pull "$OPS/pull-backups.sh" "StartCalendarIntervalHour4Minute30" ;; esac echo "✓ node installé (rôle: $ROLE)"