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

114 lines
3.2 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 User Scripts spawned by the User Scripts plugin -----------
# ----------------------------------------------------------------------------------------------
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 " ️ USER SCRIPTS STATUS"
echo "--------------------------------------------------"
echo " 🔍 Target: /tmp/user.scripts processes"
echo " 🧪 Dry Run: $DRY_RUN"
echo "=================================================="
exit 0
fi
# HEADER
echo
echo "============================================================"
echo " 🚀 USER SCRIPTS STOP STARTING"
echo "------------------------------------------------------------"
echo " 🔍 Target: User Scripts Plugin processes"
echo " 🧪 Dry Run: $DRY_RUN"
echo "============================================================"
log "️ Scanning for User Scripts processes"
# FUNCTIONS
get_user_script_pids() {
/usr/bin/ps -eo pid,cmd | grep "/tmp/user.scripts" | grep -v grep | awk '{print $1}'
}
stop_user_scripts() {
local pids
pids=$(get_user_script_pids)
if [[ -z "$pids" ]]; then
info "🟢 No running User Scripts found"
return
fi
local count=0
for pid in $pids; do
if [[ "$DRY_RUN" == true ]]; then
warn "🧪 Would kill User Script PID $pid"
else
info "🟡 Killing User Script PID $pid"
if kill "$pid" 2>/dev/null; then
info "🟢 Killed PID $pid"
else
warn "🔴 Failed to kill PID $pid (may already be gone)"
fi
fi
count=$((count + 1))
done
if [[ "$DRY_RUN" == true ]]; then
warn "🧪 Would stop $count User Script process(es)"
else
info "🟢 Process cleanup complete ($count process(es) targeted)"
fi
}
# EXECUTION
START_TIME=$(date +%s)
stop_user_scripts
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
# SUMMARY
echo
echo "============================================================"
if [[ "$DRY_RUN" == true ]]; then
echo " 🟡 USER SCRIPTS SUMMARY"
echo "------------------------------------------------------------"
echo " 🔍 Status: 🟡 DRY RUN (no processes killed)"
echo " ⏱ Duration: ${DURATION}s"
else
local remaining
remaining=$(get_user_script_pids)
if [[ -z "$remaining" ]]; then
echo " 🟢 USER SCRIPTS SUMMARY"
echo "------------------------------------------------------------"
echo " 🔍 Status: 🟢 ALL PROCESSES STOPPED"
else
echo " 🟡 USER SCRIPTS SUMMARY"
echo "------------------------------------------------------------"
echo " 🔍 Status: 🟡 SOME PROCESSES MAY STILL BE RUNNING"
fi
echo " ⏱ Duration: ${DURATION}s"
fi
echo "============================================================"
info "️ User Scripts stop operation complete"