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

93 lines
2.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
# ----------------------------------------------------------------------------------------------
# ------------------------ Stop all running Rsync processes for Unraid -------------------------
# ----------------------------------------------------------------------------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../Master.conf"
source "$SCRIPT_DIR/../common.sh"
parse_args "$@"
# STATUS MODE
if [[ "$SHOW_STATUS" == true ]]; then
echo
echo "=================================================="
echo " ️ RSYNC STOP STATUS"
echo "--------------------------------------------------"
echo " 🔄 Target: rsync processes"
echo " 🧪 Dry Run: $DRY_RUN"
echo "=================================================="
exit 0
fi
# HEADER
echo
echo "============================================================"
echo " 🚀 RSYNC STOP STARTING"
echo "------------------------------------------------------------"
echo " 🔄 Target: all rsync processes"
echo " 🧪 Dry Run: $DRY_RUN"
echo "============================================================"
log "️ Checking for running rsync processes"
# FUNCTIONS
check_rsync_running() {
pgrep -f rsync >/dev/null 2>&1
}
stop_rsync_processes() {
if [[ "$DRY_RUN" == true ]]; then
warn "🧪 Would stop all rsync processes"
return
fi
if check_rsync_running; then
info "🟡 Stopping rsync processes"
# safer than blind pkill message-only:
pkill -f rsync
sleep 1
if check_rsync_running; then
warn "🟡 Some rsync processes may still be running"
else
info "🟢 All rsync processes stopped successfully"
fi
else
info "🟢 No rsync processes currently running"
fi
}
# EXECUTION
START_TIME=$(date +%s)
stop_rsync_processes
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
# SUMMARY
echo
echo "============================================================"
if check_rsync_running; then
echo " 🟡 RSYNC STOP SUMMARY"
echo "------------------------------------------------------------"
echo " 🔄 Status: 🟡 SOME PROCESSES MAY REMAIN"
echo " ⏱ Duration: ${DURATION}s"
else
echo " 🟢 RSYNC STOP SUMMARY"
echo "------------------------------------------------------------"
echo " 🔄 Status: 🟢 ALL STOPPED"
echo " ⏱ Duration: ${DURATION}s"
fi
echo "============================================================"
info "️ Rsync stop operation complete"