43 lines
1.1 KiB
Bash
43 lines
1.1 KiB
Bash
#!/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/../common.sh"
|
|
|
|
# Load central config
|
|
load_master_conf
|
|
|
|
# Parse CLI args (supports --dry-run)
|
|
parse_args "$@"
|
|
|
|
# Functions
|
|
|
|
stop_user_scripts() {
|
|
# Get PIDs of running user scripts
|
|
local pids
|
|
pids=$(/usr/bin/ps -eo pid,cmd | grep "/tmp/user.scripts" | grep -v grep | awk '{print $1}')
|
|
|
|
if [ -z "$pids" ]; then
|
|
echo "No running user scripts found."
|
|
return
|
|
fi
|
|
|
|
for pid in $pids; do
|
|
if [ "$DRY_RUN" = true ]; then
|
|
echo "[DRY-RUN] Would kill user script with PID $pid"
|
|
else
|
|
echo "Killing user script with PID $pid"
|
|
kill "$pid"
|
|
fi
|
|
done
|
|
|
|
echo "All user scripts stopped."
|
|
}
|
|
|
|
# MAIN
|
|
echo "==== User Scripts Stop Script Started: $(date) ===="
|
|
|
|
stop_user_scripts |