all scripts are now current with common.sh v2.1
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
#!/bin/bash
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# --------------------------------- Mover Stop Script ------------------------------------------
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# Safely stops the unRAID mover process with a user warning before halting.
|
||||
# Timeout before stopping is configured in Master.conf under MOVER_STOP_TIMEOUT.
|
||||
# Supports --dry-run to preview what would happen without making changes.
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
source "$SCRIPT_DIR/../Master.conf"
|
||||
source "$SCRIPT_DIR/../common.sh"
|
||||
|
||||
parse_args "$@"
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ━━━ $ICON_GEAR Setup ━━━
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "━━━ $ICON_GEAR Setup ━━━"
|
||||
|
||||
# ROOT CHECK
|
||||
if [[ "$EUID" -ne 0 ]]; then
|
||||
error "Must be run as root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
success "Running as root"
|
||||
|
||||
# Validate MOVER_STOP_TIMEOUT is a valid integer before using it
|
||||
validate_int MOVER_STOP_TIMEOUT "$MOVER_STOP_TIMEOUT"
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ━━━ $ICON_SUMMARY Status ━━━
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
if [[ "$SHOW_STATUS" == true ]]; then
|
||||
echo ""
|
||||
echo "━━━━━ $ICON_SUMMARY STATUS ━━━━━"
|
||||
echo "$ICON_MOVER Timeout: ${MOVER_STOP_TIMEOUT}s"
|
||||
echo "$ICON_GEAR Dry Run: $DRY_RUN"
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# FUNCTIONS
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
|
||||
# Returns 0 if the unRAID mover process is currently running, 1 if not.
|
||||
check_mover_running() {
|
||||
pgrep -f "emhttp.*Mover" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Broadcasts a wall message to all logged in users warning mover is stopping.
|
||||
notify_users() {
|
||||
warn "Notifying users — mover stopping in ${MOVER_STOP_TIMEOUT}s"
|
||||
wall "$ICON_WARN unRAID Mover will stop in ${MOVER_STOP_TIMEOUT} second(s)."
|
||||
}
|
||||
|
||||
# Sends SIGTERM to the mover process via pkill.
|
||||
# Skips if dry run is active.
|
||||
stop_mover() {
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
warn "DRY RUN — would stop unRAID Mover process"
|
||||
return
|
||||
fi
|
||||
|
||||
info "Stopping unRAID Mover..."
|
||||
|
||||
if pkill -f "emhttp.*Mover"; then
|
||||
success "Mover stopped"
|
||||
else
|
||||
warn "Could not stop mover — may have already stopped"
|
||||
fi
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ━━━ $ICON_MOVER Mover Stop ━━━
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "━━━ $ICON_MOVER Mover Stop ━━━"
|
||||
echo "$ICON_MOVER Timeout: ${MOVER_STOP_TIMEOUT}s"
|
||||
echo "$ICON_GEAR Dry Run: $DRY_RUN"
|
||||
echo ""
|
||||
|
||||
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no changes will be made"
|
||||
|
||||
START=$(date +%s)
|
||||
|
||||
if check_mover_running; then
|
||||
info "$ICON_MOVER Mover is running"
|
||||
notify_users
|
||||
info "Waiting ${MOVER_STOP_TIMEOUT}s before stopping..."
|
||||
sleep "$MOVER_STOP_TIMEOUT"
|
||||
stop_mover
|
||||
else
|
||||
info "$ICON_MOVER Mover is not running — nothing to do"
|
||||
fi
|
||||
|
||||
END=$(date +%s)
|
||||
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
# ━━━ $ICON_SUMMARY Summary ━━━
|
||||
# -----------------------------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "━━━━━ $ICON_SUMMARY MOVER STOP SUMMARY ━━━━━"
|
||||
echo "$ICON_TIME Duration: $(format_duration $((END - START)))"
|
||||
if check_mover_running; then
|
||||
echo "$ICON_ERROR Status: $ICON_ERROR STILL RUNNING"
|
||||
else
|
||||
echo "$ICON_DONE Status: $ICON_SUCCESS STOPPED / NOT RUNNING"
|
||||
fi
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
Reference in New Issue
Block a user