Files
Varaverk/unRAID Essentials/mover-stop.sh
T
2026-03-27 16:50:20 +00:00

119 lines
3.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -e
# ----------------------------------------------------------------------------------------------
# --------------------------- Mover Stop Script for Unraid -------------------------------------
# ----------------------------------------------------------------------------------------------
# ---------------- User Variables, Please adjust in Master.conf as needed ----------------------
# ----------------------------------------------------------------------------------------------
#
# User variables can be adjusted in Master.conf
#
# Scripts now just contain runtime logic
#
# This new setup allows for profiles and arguments to use the core script
# Use arguments in unRAID User Plugin for directory
# Example: /mnt/user/appdata/unraid_scripts/Rsync/rsync.sh --dry-run
# ----------------------------------------------------------------------------------------------
# -------------- End Of User Variables, Please adjust in Master.conf as needed -----------------
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh"
parse_args "$@"
# CONFIG
MOVER_STOP_TIMEOUT=${MOVER_STOP_TIMEOUT:-30}
validate_int MOVER_STOP_TIMEOUT "$MOVER_STOP_TIMEOUT"
# STATUS MODE
if [[ "$SHOW_STATUS" == true ]]; then
echo
echo "=================================================="
echo " ️ MOVER STOP STATUS"
echo "--------------------------------------------------"
echo " ⏱ Timeout: ${MOVER_STOP_TIMEOUT}s"
echo " 📡 Dry Run: $DRY_RUN"
echo "=================================================="
exit 0
fi
# HEADER
echo
echo "============================================================"
echo " 🚀 MOVER STOP STARTING"
echo "------------------------------------------------------------"
echo " ⏱ Timeout: ${MOVER_STOP_TIMEOUT}s"
echo " 🧪 Dry Run: $DRY_RUN"
echo "============================================================"
log "️ Checking mover status"
# FUNCTIONS
check_mover_running() {
pgrep -f "emhttp.*Mover" >/dev/null 2>&1
}
notify_users() {
warn "🟡 Notifying users: mover stopping soon"
wall "⚠️ Unraid Mover will stop in ${MOVER_STOP_TIMEOUT} second(s)."
}
stop_mover() {
if [[ "$DRY_RUN" == true ]]; then
warn "🧪 Would stop Unraid Mover process"
return
fi
info "🟡 Stopping Unraid Mover process"
if pkill -f "emhttp.*Mover"; then
info "🟢 Mover stopped successfully"
else
warn "🔴 Failed to stop mover (may not be running)"
fi
}
# EXECUTION
START_TIME=$(date +%s)
if check_mover_running; then
info "🟡 Mover is running"
notify_users
info "⏱ Waiting ${MOVER_STOP_TIMEOUT}s before stopping"
sleep "$MOVER_STOP_TIMEOUT"
stop_mover
else
info "🟢 Mover is not running"
fi
# FINALIZE
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
# SUMMARY
echo
echo "============================================================"
if check_mover_running; then
echo " 🟡 MOVER STOP SUMMARY"
echo "------------------------------------------------------------"
echo " ⏱ Duration: ${DURATION}s"
echo " 📡 Status: 🟡 STILL RUNNING OR UNCERTAIN"
else
echo " 🟢 MOVER STOP SUMMARY"
echo "------------------------------------------------------------"
echo " ⏱ Duration: ${DURATION}s"
echo " 📡 Status: 🟢 STOPPED / NOT RUNNING"
fi
echo "============================================================"
info "️ Mover stop operation complete"