111 lines
4.3 KiB
Bash
111 lines
4.3 KiB
Bash
#!/bin/bash
|
|
# -----------------------------------------------------------------------------------------------
|
|
# --------------------------------- Array Start Orchestrator -----------------------------------
|
|
# -----------------------------------------------------------------------------------------------
|
|
# Single entry point for "At Startup of Array" in User Scripts plugin.
|
|
# Launches everything configured in ARRAY_START_SCRIPTS in Master.conf.
|
|
#
|
|
# What it launches (configured in Master.conf ARRAY_START_SCRIPTS):
|
|
# Transcodes/ramdisk_setup.sh — creates tmpfs + symlink before Emby starts (one-shot)
|
|
# unRAID_Essentials/docker_syslog_filter.sh — suppress veth log noise (one-shot)
|
|
# unRAID_Essentials/php_fpm_max_children.sh — WebGUI performance tuning (one-shot)
|
|
# Docker_Essentials/docker_network_connect.sh — ensure networks exist + connect containers (one-shot)
|
|
# unRAID_Essentials/system_watchdog.sh — system health monitor (continuous loop)
|
|
# Docker_Essentials/docker_watchdog.sh — container health monitor (continuous loop)
|
|
# Failover/failover.sh — mutual failover monitor (continuous loop)
|
|
#
|
|
# One-shot scripts run and exit naturally — array_start.sh confirms completion.
|
|
# Continuous scripts run until array stops or SIGTERM received.
|
|
# This orchestrator exits after launching all scripts — unRAID sees it complete normally.
|
|
#
|
|
# Add or remove scripts: edit ARRAY_START_SCRIPTS in Master.conf.
|
|
# Order matters — ramdisk first, network before watchdogs, watchdogs before failover.
|
|
# No changes to this script ever needed.
|
|
# -----------------------------------------------------------------------------------------------
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
ECOSYSTEM_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
|
|
source "$ECOSYSTEM_ROOT/Master.conf"
|
|
source "$ECOSYSTEM_ROOT/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="$ECOSYSTEM_ROOT/$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 "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" |