all scripts are now current with common.sh v2.1

This commit is contained in:
2026-04-08 17:36:58 -04:00
parent 429de6b10e
commit 9a7a28055f
20 changed files with 1356 additions and 1105 deletions
+129
View File
@@ -0,0 +1,129 @@
#!/bin/bash
# -----------------------------------------------------------------------------------------------
# --------------------------------- Clear Logs Script ------------------------------------------
# -----------------------------------------------------------------------------------------------
# Clears unRAID system logs and Docker container logs safely.
# Log file paths are configured in Master.conf under LOG_FILES.
# Supports --dry-run to preview what would be cleared 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"
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Status ━━━
# -----------------------------------------------------------------------------------------------
if [[ "$SHOW_STATUS" == true ]]; then
echo ""
echo "━━━━━ $ICON_SUMMARY STATUS ━━━━━"
echo "$ICON_HEALTH System Logs: ${LOG_FILES[*]}"
echo "$ICON_DOCKER Docker Logs: /var/lib/docker/containers"
echo "$ICON_GEAR Dry Run: $DRY_RUN"
echo "━━━━━━━━━━━━━━━━━━━━━━━"
exit 0
fi
# -----------------------------------------------------------------------------------------------
# FUNCTIONS
# -----------------------------------------------------------------------------------------------
# Clears a single log file if it exists.
# Skips with a warning if the file is not found.
clear_file() {
local file="$1"
if [[ ! -f "$file" ]]; then
warn "Not found: $file — skipping"
return
fi
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would clear: $file"
else
: > "$file"
success "Cleared: $file"
fi
}
# Finds and clears all Docker container json log files.
# Skips gracefully if Docker directory or log files are not found.
clear_docker_logs() {
if [[ ! -d /var/lib/docker/containers ]]; then
warn "$ICON_DOCKER Docker directory not found — skipping"
return
fi
local files
files=$(find /var/lib/docker/containers/ -name "*-json.log" 2>/dev/null || true)
if [[ -z "$files" ]]; then
warn "$ICON_DOCKER No Docker logs found — skipping"
return
fi
while IFS= read -r file; do
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would clear Docker log: $file"
else
: > "$file"
success "Cleared Docker log: $(basename "$(dirname "$file")")"
fi
done <<< "$files"
}
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_HEALTH Clear Logs ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━ $ICON_HEALTH Clear Logs ━━━"
echo "$ICON_HEALTH System Logs: ${LOG_FILES[*]}"
echo "$ICON_DOCKER Docker Logs: enabled"
echo "$ICON_GEAR Dry Run: $DRY_RUN"
echo ""
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no changes will be made"
START=$(date +%s)
for logfile in "${LOG_FILES[@]}"; do
clear_file "$logfile"
done
echo ""
echo "━━━ $ICON_DOCKER Docker ━━━"
clear_docker_logs
END=$(date +%s)
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Summary ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━━━ $ICON_SUMMARY LOG CLEANER SUMMARY ━━━━━"
echo "$ICON_HEALTH System Logs: ${LOG_FILES[*]}"
echo "$ICON_DOCKER Docker Logs: $([[ "$DRY_RUN" == true ]] && echo "skipped (dry run)" || echo "cleared")"
echo "$ICON_TIME Duration: $(format_duration $((END - START)))"
if [[ "$DRY_RUN" == true ]]; then
echo "$ICON_WARN Status: DRY RUN — no changes made"
else
echo "$ICON_DONE Status: $ICON_SUCCESS DONE"
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+118
View File
@@ -0,0 +1,118 @@
#!/bin/bash
# -----------------------------------------------------------------------------------------------
# --------------------------------- Docker Syslog Filter ---------------------------------------
# -----------------------------------------------------------------------------------------------
# Suppresses noisy Docker veth/docker0 syslog messages on unRAID boot.
# Creates an rsyslog filter file and restarts the rsyslog service.
# Filter file path is configured in Master.conf under FILTER_FILE.
# Supports --dry-run to preview what would be done 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"
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Status ━━━
# -----------------------------------------------------------------------------------------------
if [[ "$SHOW_STATUS" == true ]]; then
echo ""
echo "━━━━━ $ICON_SUMMARY STATUS ━━━━━"
echo "$ICON_HEALTH Filter File: $FILTER_FILE"
echo "$ICON_CONTAINERS Targets: veth, docker0"
echo "$ICON_GEAR Dry Run: $DRY_RUN"
echo "━━━━━━━━━━━━━━━━━━━━━━━"
exit 0
fi
# -----------------------------------------------------------------------------------------------
# FUNCTIONS
# -----------------------------------------------------------------------------------------------
# Creates the rsyslog filter file that suppresses veth and docker0 noise.
# Filter is written to FILTER_FILE defined in Master.conf.
create_filter() {
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would create filter file: $FILTER_FILE"
return
fi
info "Writing rsyslog filter file: $FILTER_FILE"
cat <<'EOF' > "$FILTER_FILE"
if ($msg contains "veth" or $msg contains "docker0") then {
stop
}
EOF
success "Filter file written"
}
# Restarts the rsyslog service to apply the new filter.
# Uses unRAID's native rc.rsyslogd script.
restart_rsyslog() {
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would restart rsyslog service"
return
fi
info "Restarting rsyslog..."
if /etc/rc.d/rc.rsyslogd restart; then
success "rsyslog restarted"
else
error "Failed to restart rsyslog"
exit 1
fi
}
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_HEALTH Syslog Filter ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━ $ICON_HEALTH Syslog Filter ━━━"
echo "$ICON_HEALTH Filter File: $FILTER_FILE"
echo "$ICON_CONTAINERS Targets: veth / docker0"
echo "$ICON_GEAR Dry Run: $DRY_RUN"
echo ""
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no changes will be made"
START=$(date +%s)
create_filter
restart_rsyslog
END=$(date +%s)
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Summary ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━━━ $ICON_SUMMARY SYSLOG FILTER SUMMARY ━━━━━"
echo "$ICON_HEALTH Filter File: $FILTER_FILE"
echo "$ICON_CONTAINERS Targets: veth / docker0"
echo "$ICON_TIME Duration: $(format_duration $((END - START)))"
if [[ "$DRY_RUN" == true ]]; then
echo "$ICON_WARN Status: DRY RUN — no changes made"
else
echo "$ICON_DONE Status: $ICON_SUCCESS DONE"
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+114
View File
@@ -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 "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+131
View File
@@ -0,0 +1,131 @@
#!/bin/bash
# -----------------------------------------------------------------------------------------------
# ----------------------------- PHP-FPM Max Children Script ------------------------------------
# -----------------------------------------------------------------------------------------------
# Persistently sets PHP-FPM pm.max_children on unRAID.
# Config file path and max children value are set in Master.conf.
# Supports --dry-run to preview what would be changed 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"
# VALIDATION
validate_int PHP_MAX_CHILDREN "$PHP_MAX_CHILDREN"
require_var PHP_CONF
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Status ━━━
# -----------------------------------------------------------------------------------------------
if [[ "$SHOW_STATUS" == true ]]; then
echo ""
echo "━━━━━ $ICON_SUMMARY STATUS ━━━━━"
echo "$ICON_GEAR Config File: $PHP_CONF"
echo "$ICON_PHP Max Children: $PHP_MAX_CHILDREN"
echo "$ICON_GEAR Dry Run: $DRY_RUN"
echo "━━━━━━━━━━━━━━━━━━━━━━━"
exit 0
fi
# -----------------------------------------------------------------------------------------------
# FUNCTIONS
# -----------------------------------------------------------------------------------------------
# Applies pm.max_children to the PHP-FPM config file and restarts the service.
# Verifies the value was applied correctly after restart.
# Skips all changes if dry run is active.
apply_php_max_children() {
local target="pm.max_children = $PHP_MAX_CHILDREN"
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would set pm.max_children = $PHP_MAX_CHILDREN in $PHP_CONF"
warn "DRY RUN — would restart PHP-FPM service"
return
fi
# Verify config file exists before attempting changes
if [[ ! -f "$PHP_CONF" ]]; then
error "PHP config file not found: $PHP_CONF"
exit 1
fi
info "Applying pm.max_children = $PHP_MAX_CHILDREN..."
if sed -i "s/^pm\.max_children.*/$target/" "$PHP_CONF"; then
success "Config updated"
else
error "Failed to update PHP config: $PHP_CONF"
exit 1
fi
info "Restarting PHP-FPM..."
if /etc/rc.d/rc.php-fpm restart; then
success "PHP-FPM restarted"
else
error "PHP-FPM restart failed"
exit 1
fi
# Verify the value was applied correctly
local current
current=$(grep -E "^pm\.max_children" "$PHP_CONF" || true)
if [[ -n "$current" ]]; then
success "Verified: $current"
logger "Userscript: PHP-FPM updated → $current"
else
warn "Could not verify configuration value — check $PHP_CONF manually"
fi
}
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_PHP PHP-FPM Config ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━ $ICON_PHP PHP-FPM Config ━━━"
echo "$ICON_GEAR Config File: $PHP_CONF"
echo "$ICON_PHP Max Children: $PHP_MAX_CHILDREN"
echo "$ICON_GEAR Dry Run: $DRY_RUN"
echo ""
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no changes will be made"
START=$(date +%s)
apply_php_max_children
END=$(date +%s)
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Summary ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━━━ $ICON_SUMMARY PHP-FPM SUMMARY ━━━━━"
echo "$ICON_GEAR Config File: $PHP_CONF"
echo "$ICON_PHP Max Children: $PHP_MAX_CHILDREN"
echo "$ICON_TIME Duration: $(format_duration $((END - START)))"
if [[ "$DRY_RUN" == true ]]; then
echo "$ICON_WARN Status: DRY RUN — no changes made"
else
echo "$ICON_DONE Status: $ICON_SUCCESS DONE"
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+192
View File
@@ -0,0 +1,192 @@
#!/bin/bash
# -----------------------------------------------------------------------------------------------
# --------------------------------- Rsync Stop Script ------------------------------------------
# -----------------------------------------------------------------------------------------------
# Stops all running rsync processes on both the local and remote server.
# Used during array stop or manually when rsync needs to be forcefully terminated.
# If rsync processes were killed locally, checks all profile containers and restarts any
# that were left stopped by the interrupted rsync run.
# Remote is killed but left in whatever container state it is in — secondary is self-healing.
# Supports --dry-run to preview what would be killed 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 ━━━"
detect_hosts
resolve_remote_ip
# Check connectivity but do not exit on failure — remote may already be going down
REMOTE_REACHABLE=true
if ! ping -c1 -W3 "$REMOTE_SERVER" &>/dev/null; then
warn "$ICON_PING Remote $REMOTE_SERVER_NAME is unreachable — will skip remote kill"
REMOTE_REACHABLE=false
else
info "$ICON_PING $REMOTE_SERVER_NAME is reachable"
fi
[[ "$SHOW_STATUS" == true ]] && show_status && exit 0
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no changes will be made"
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_STOP Local Rsync ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━ $ICON_STOP Local Rsync ━━━"
LOCAL_KILLED=false
LOCAL_PIDS=$(pgrep -x rsync || true)
if [[ -z "$LOCAL_PIDS" ]]; then
info "No rsync processes running locally — nothing to kill"
else
info "Found rsync processes locally: $(echo "$LOCAL_PIDS" | tr '\n' ' ')"
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would kill local rsync processes"
else
if pkill -x rsync; then
success "Local rsync processes killed"
LOCAL_KILLED=true
else
warn "pkill returned non-zero — processes may have already exited"
fi
fi
fi
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_STOP Remote Rsync ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━ $ICON_STOP Remote Rsync ($REMOTE_SERVER_NAME) ━━━"
REMOTE_KILLED=false
if [[ "$REMOTE_REACHABLE" == false ]]; then
warn "Skipping remote kill — $REMOTE_SERVER_NAME unreachable"
else
REMOTE_PIDS=$(ssh -i "$SSH_KEY" root@"$REMOTE_SERVER" \
"pgrep -x rsync || true" 2>/dev/null || true)
if [[ -z "$REMOTE_PIDS" ]]; then
info "No rsync processes running on $REMOTE_SERVER_NAME — nothing to kill"
else
info "Found rsync processes on $REMOTE_SERVER_NAME: $(echo "$REMOTE_PIDS" | tr '\n' ' ')"
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would kill remote rsync processes"
else
if ssh -i "$SSH_KEY" root@"$REMOTE_SERVER" "pkill -x rsync || true" 2>/dev/null; then
success "Remote rsync processes killed"
REMOTE_KILLED=true
else
warn "Remote pkill returned non-zero — processes may have already exited"
fi
fi
fi
fi
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_START $ICON_CONTAINERS Local Container Recovery ━━━
# Only runs if rsync was actually killed locally — containers may have been left stopped
# by the interrupted rsync run. Checks all containers across all profiles and restarts
# any that are currently stopped. Remote containers are left in their current state.
# -----------------------------------------------------------------------------------------------
CONTAINERS_RESTARTED=()
if [[ "$LOCAL_KILLED" == true ]]; then
echo ""
echo "━━━ $ICON_START $ICON_CONTAINERS Local Container Recovery ━━━"
info "Rsync was killed locally — checking all profile containers..."
# Build deduplicated list of all containers across all profiles
declare -A SEEN
ALL_CONTAINERS=()
for profile_containers in "${PROFILE_CRITICAL_CONTAINER_NAMES[@]}"; do
read -r -a container_list <<< "$profile_containers"
for c in "${container_list[@]}"; do
[[ -z "$c" ]] && continue
if [[ -z "${SEEN[$c]:-}" ]]; then
SEEN[$c]=1
ALL_CONTAINERS+=("$c")
fi
done
done
if [[ ${#ALL_CONTAINERS[@]} -eq 0 ]]; then
info "No containers defined across any profile — skipping recovery"
else
for c in "${ALL_CONTAINERS[@]}"; do
info "Checking $c..."
STATUS=$(docker inspect -f '{{.State.Running}}' "$c" 2>/dev/null || echo "unknown")
if [[ "$STATUS" == "true" ]]; then
echo "$ICON_RUNNING $c is running — no action needed"
elif [[ "$STATUS" == "false" ]]; then
echo "$ICON_NOT_RUNNING $c is stopped — restarting..."
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would restart $c"
else
if docker start "$c" >/dev/null 2>&1; then
echo "$ICON_STARTED $c restarted"
CONTAINERS_RESTARTED+=("$c")
else
error "Failed to restart $c"
fi
fi
else
warn "$c state unknown — may not exist on this machine, skipping"
fi
done
fi
elif [[ "$DRY_RUN" == false ]]; then
info "No local rsync was killed — skipping container recovery"
fi
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Summary ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━━━ $ICON_SUMMARY RSYNC STOP SUMMARY ━━━━━"
echo "$ICON_HOST Local ($LOCAL_SERVER_NAME):"
if [[ "$LOCAL_KILLED" == true ]]; then
echo " $ICON_STOPPED Rsync killed"
elif [[ "$DRY_RUN" == true ]]; then
echo " $ICON_WARN Dry run — no changes made"
else
echo " $ICON_SUCCESS No rsync running"
fi
echo "$ICON_NET Remote ($REMOTE_SERVER_NAME):"
if [[ "$REMOTE_REACHABLE" == false ]]; then
echo " $ICON_WARN Unreachable — state unknown"
elif [[ "$REMOTE_KILLED" == true ]]; then
echo " $ICON_STOPPED Rsync killed"
else
echo " $ICON_SUCCESS No rsync running"
fi
if [[ ${#CONTAINERS_RESTARTED[@]} -gt 0 ]]; then
echo "$ICON_CONTAINERS Containers restarted locally:"
for c in "${CONTAINERS_RESTARTED[@]}"; do
echo " $ICON_STARTED $c"
done
elif [[ "$LOCAL_KILLED" == true ]]; then
echo "$ICON_CONTAINERS No containers needed restarting"
fi
echo "$ICON_TIME Dry Run: $DRY_RUN"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+159
View File
@@ -0,0 +1,159 @@
#!/bin/bash
# -----------------------------------------------------------------------------------------------
# --------------------------------- Server Reboot Script ---------------------------------------
# -----------------------------------------------------------------------------------------------
# Gracefully reboots the unRAID server with a configurable user warning delay.
# Stops Docker and VM Manager cleanly before issuing reboot.
# Reboot delay is configured in Master.conf under REBOOT_SLEEP.
# Supports --dry-run to walk through the sequence without actually rebooting.
# -----------------------------------------------------------------------------------------------
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"
# VALIDATION
validate_int REBOOT_SLEEP "$REBOOT_SLEEP"
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Status ━━━
# -----------------------------------------------------------------------------------------------
if [[ "$SHOW_STATUS" == true ]]; then
echo ""
echo "━━━━━ $ICON_SUMMARY STATUS ━━━━━"
echo "$ICON_REBOOT Delay: ${REBOOT_SLEEP}s"
echo "$ICON_GEAR Dry Run: $DRY_RUN"
echo "━━━━━━━━━━━━━━━━━━━━━━━"
exit 0
fi
# -----------------------------------------------------------------------------------------------
# FUNCTIONS
# -----------------------------------------------------------------------------------------------
# Broadcasts a wall message warning all logged in users of the upcoming reboot.
notify_users() {
warn "Notifying users — reboot in ${REBOOT_SLEEP}s"
wall "$ICON_WARN unRAID server will reboot in ${REBOOT_SLEEP} second(s). Save your work."
}
# Stops the Docker service cleanly.
# Warns but continues if Docker is already stopped or fails — shutdown must proceed.
stop_docker() {
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would stop Docker service"
return
fi
info "Stopping Docker service..."
if /etc/rc.d/rc.docker stop; then
success "Docker stopped"
else
warn "Docker stop failed or already stopped — continuing"
fi
}
# Stops the VM Manager (libvirt) cleanly.
# Warns but continues if libvirt is already stopped or fails — shutdown must proceed.
stop_vm_manager() {
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would stop VM Manager (libvirt)"
return
fi
info "Stopping VM Manager..."
if /etc/rc.d/rc.libvirt stop; then
success "VM Manager stopped"
else
warn "VM Manager stop failed or already stopped — continuing"
fi
}
# Flushes filesystem buffers to disk before reboot.
sync_disks() {
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would sync filesystem buffers"
return
fi
info "Syncing disks..."
if sync; then
success "Disk sync complete"
else
warn "Sync returned an error — continuing"
fi
}
# Issues the system reboot command.
# System will not return from this call unless dry-run is active.
reboot_system() {
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would reboot system now"
return
fi
echo ""
echo "$ICON_REBOOT Rebooting system NOW..."
/sbin/reboot
}
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_REBOOT Reboot Sequence ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━ $ICON_REBOOT Reboot Sequence ━━━"
echo "$ICON_REBOOT Delay: ${REBOOT_SLEEP}s"
echo "$ICON_GEAR Dry Run: $DRY_RUN"
echo ""
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no changes will be made"
START=$(date +%s)
if [[ "$REBOOT_SLEEP" -gt 0 ]]; then
notify_users
info "Waiting ${REBOOT_SLEEP}s before shutdown sequence..."
sleep "$REBOOT_SLEEP"
fi
stop_docker
stop_vm_manager
sync_disks
reboot_system
# NOTE: system will not reach here unless --dry-run is active
END=$(date +%s)
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Summary ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━━━ $ICON_SUMMARY REBOOT SUMMARY ━━━━━"
echo "$ICON_REBOOT Delay: ${REBOOT_SLEEP}s"
echo "$ICON_TIME Duration: $(format_duration $((END - START)))"
if [[ "$DRY_RUN" == true ]]; then
echo "$ICON_WARN Status: DRY RUN — no reboot executed"
else
echo "$ICON_REBOOT Status: $ICON_WARN SYSTEM SHOULD BE REBOOTING"
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+125
View File
@@ -0,0 +1,125 @@
#!/bin/bash
# -----------------------------------------------------------------------------------------------
# --------------------------------- User Script Stop -------------------------------------------
# -----------------------------------------------------------------------------------------------
# Stops all running User Script processes spawned by the unRAID User Scripts plugin.
# Identifies processes by their /tmp/user.scripts path signature.
# Supports --dry-run to preview what would be killed 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"
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Status ━━━
# -----------------------------------------------------------------------------------------------
if [[ "$SHOW_STATUS" == true ]]; then
echo ""
echo "━━━━━ $ICON_SUMMARY STATUS ━━━━━"
echo "$ICON_PLUGIN Target: /tmp/user.scripts processes"
echo "$ICON_GEAR Dry Run: $DRY_RUN"
echo "━━━━━━━━━━━━━━━━━━━━━━━"
exit 0
fi
# -----------------------------------------------------------------------------------------------
# FUNCTIONS
# -----------------------------------------------------------------------------------------------
# Returns PIDs of all processes running under /tmp/user.scripts
# These are processes spawned by the unRAID User Scripts plugin.
get_user_script_pids() {
/usr/bin/ps -eo pid,cmd | grep "/tmp/user.scripts" | grep -v grep | awk '{print $1}'
}
# Kills all running User Script processes one by one.
# Reports each PID killed or skipped in dry run mode.
# Checks remaining processes after kill to confirm cleanup.
stop_user_scripts() {
local pids
pids=$(get_user_script_pids)
if [[ -z "$pids" ]]; then
info "$ICON_PLUGIN No running User Script processes found — nothing to do"
return
fi
local count=0
for pid in $pids; do
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would kill User Script PID $pid"
else
info "Killing User Script PID $pid..."
if kill "$pid" 2>/dev/null; then
success "Killed PID $pid"
else
warn "Could not kill PID $pid — may have already exited"
fi
fi
count=$((count + 1))
done
if [[ "$DRY_RUN" == true ]]; then
warn "DRY RUN — would have targeted $count process(es)"
else
info "$count process(es) targeted"
fi
}
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_PLUGIN User Script Stop ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━ $ICON_PLUGIN User Script Stop ━━━"
echo "$ICON_PLUGIN Target: User Scripts Plugin processes"
echo "$ICON_GEAR Dry Run: $DRY_RUN"
echo ""
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no changes will be made"
START=$(date +%s)
stop_user_scripts
END=$(date +%s)
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Summary ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━━━ $ICON_SUMMARY USER SCRIPTS STOP SUMMARY ━━━━━"
echo "$ICON_TIME Duration: $(format_duration $((END - START)))"
if [[ "$DRY_RUN" == true ]]; then
echo "$ICON_WARN Status: DRY RUN — no processes killed"
else
REMAINING=$(get_user_script_pids)
if [[ -z "$REMAINING" ]]; then
echo "$ICON_DONE Status: $ICON_SUCCESS ALL PROCESSES STOPPED"
else
echo "$ICON_WARN Status: $ICON_WARN SOME PROCESSES MAY STILL BE RUNNING"
fi
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
+103
View File
@@ -0,0 +1,103 @@
#!/bin/bash
# -----------------------------------------------------------------------------------------------
# --------------------------------- ZFS Memory Snapshot ----------------------------------------
# -----------------------------------------------------------------------------------------------
# Captures a point-in-time snapshot of ZFS ARC statistics and system memory usage.
# Read-only diagnostic tool — no changes are made to the system regardless of flags.
# Dry run mode still collects and displays data since no modifications occur.
# -----------------------------------------------------------------------------------------------
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 ━━━"
info "$ICON_ZFS ZFS ARC + Memory Snapshot"
info "$ICON_TIME $(date)"
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Status ━━━
# -----------------------------------------------------------------------------------------------
if [[ "$SHOW_STATUS" == true ]]; then
echo ""
echo "━━━━━ $ICON_SUMMARY STATUS ━━━━━"
echo "$ICON_ZFS Mode: Read-only diagnostics"
echo "$ICON_MEM Source: ZFS ARC + system memory"
echo "$ICON_GEAR Dry Run: $DRY_RUN"
echo "━━━━━━━━━━━━━━━━━━━━━━━"
exit 0
fi
# -----------------------------------------------------------------------------------------------
# FUNCTIONS
# -----------------------------------------------------------------------------------------------
# Reads ZFS ARC statistics from the kernel stats interface.
# Filters for the most useful ARC metrics — size, hits, misses and metadata.
# Skips gracefully if ZFS is not available on this system.
show_zfs_arc() {
echo ""
echo "━━━ $ICON_ZFS ZFS ARC Stats ━━━"
if [[ ! -r /proc/spl/kstat/zfs/arcstats ]]; then
warn "ZFS arcstats not available on this system — is ZFS loaded?"
return
fi
grep -iE '^(c|size|hits|misses|arc_meta_used|demand_metadata_misses|mru_ghost_metadata|mfu_ghost_metadata)' \
/proc/spl/kstat/zfs/arcstats 2>/dev/null || warn "Unable to read ARC stats"
}
# Reads current system memory and swap usage using free.
# Skips gracefully if free is not available.
show_memory_status() {
echo ""
echo "━━━ $ICON_MEM Memory Status ━━━"
if ! command -v free >/dev/null 2>&1; then
warn "free command not available on this system"
return
fi
free -h | awk '
NR==1 { print $0 }
/Mem:/ { print $0 }
/Swap:/ { print $0 }'
}
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_ZFS Snapshot ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━ $ICON_ZFS Snapshot ━━━"
echo "$ICON_ZFS Source: ZFS ARC + system memory"
echo "$ICON_GEAR Dry Run: $DRY_RUN"
echo ""
[[ "$DRY_RUN" == true ]] && warn "DRY RUN — this script is read-only, data will still be collected"
START=$(date +%s)
show_zfs_arc
show_memory_status
END=$(date +%s)
# -----------------------------------------------------------------------------------------------
# ━━━ $ICON_SUMMARY Summary ━━━
# -----------------------------------------------------------------------------------------------
echo ""
echo "━━━━━ $ICON_SUMMARY SNAPSHOT SUMMARY ━━━━━"
echo "$ICON_ZFS Source: ZFS ARC + system memory"
echo "$ICON_GEAR Mode: READ-ONLY — no changes made"
echo "$ICON_TIME Duration: $(format_duration $((END - START)))"
echo "$ICON_DONE Status: $ICON_SUCCESS DONE"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"