#!/bin/bash # ----------------------------------------------------------------------------------------------- # --------------------------------- Array Start Orchestrator ----------------------------------- # ----------------------------------------------------------------------------------------------- # Launches all scripts configured in ARRAY_START_SCRIPTS when the unRAID array comes online. # Set this script to run at "Startup of Array" in the User Scripts plugin. # # Each script is launched as a background process: # One-shot scripts (ramdisk_setup, syslog_filter etc.) run and exit naturally # Continuous scripts (system_watchdog, docker_watchdog, failover) run until array stops # # Scripts are launched in the order defined in ARRAY_START_SCRIPTS in Master.conf. # Order matters — ramdisk before Emby, network before watchdogs, watchdogs before failover. # # To add or remove a script: edit ARRAY_START_SCRIPTS in Master.conf. # No changes to this script needed. # # Logs: each script logs its own output independently. # This orchestrator exits after launching all scripts — unRAID sees it complete normally. # ----------------------------------------------------------------------------------------------- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/Master.conf" source "$SCRIPT_DIR/common.sh" # ----------------------------------------------------------------------------------------------- # ━━━ $ICON_GEAR Setup ━━━ # ----------------------------------------------------------------------------------------------- echo "" echo "━━━ $ICON_GEAR Array Start — $(date '+%Y-%m-%d %H:%M:%S') ━━━" if [[ "$EUID" -ne 0 ]]; then error "Must be run as root" exit 1 fi success "Running as root" SCRIPT_COUNT=${#ARRAY_START_SCRIPTS[@]} info "Launching $SCRIPT_COUNT script(s)..." echo "" LAUNCHED=0 FAILED=0 for relative_path in "${ARRAY_START_SCRIPTS[@]}"; do [[ -z "$relative_path" ]] && continue SCRIPT_PATH="$SCRIPT_DIR/$relative_path" SCRIPT_NAME=$(basename "$SCRIPT_PATH") if [[ ! -f "$SCRIPT_PATH" ]]; then error "$SCRIPT_NAME — not found at $SCRIPT_PATH" ((FAILED++)) continue fi if [[ ! -x "$SCRIPT_PATH" ]]; then error "$SCRIPT_NAME — not executable" ((FAILED++)) continue fi info "$ICON_START Launching $SCRIPT_NAME..." bash "$SCRIPT_PATH" & PID=$! # Brief pause to let script initialize and catch immediate failures sleep 1 if kill -0 "$PID" 2>/dev/null; then success "$SCRIPT_NAME — running (PID $PID)" ((LAUNCHED++)) else # Script exited — check if it was a one-shot (exit 0) or a failure wait "$PID" EXIT_CODE=$? if [[ "$EXIT_CODE" -eq 0 ]]; then success "$SCRIPT_NAME — completed (one-shot)" ((LAUNCHED++)) else error "$SCRIPT_NAME — exited with code $EXIT_CODE" ((FAILED++)) fi fi done # ----------------------------------------------------------------------------------------------- # ━━━ $ICON_SUMMARY Summary ━━━ # ----------------------------------------------------------------------------------------------- echo "" echo "━━━━━ $ICON_SUMMARY ARRAY START SUMMARY ━━━━━" echo "$ICON_SUCCESS Launched: $LAUNCHED" echo "$ICON_ERROR Failed: $FAILED" echo "$ICON_TIME Time: $(date '+%H:%M:%S')" echo "" if [[ "$FAILED" -gt 0 ]]; then echo "$ICON_WARN Status: $FAILED script(s) failed to launch — check logs" notify "Array start on $(hostname) — $FAILED script(s) failed to launch" "Array Start" "warning" else echo "$ICON_DONE Status: $ICON_SUCCESS All scripts launched" fi echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"