From 6cc26c8fb957c84e0c1d59cf5c7445119f8885aa Mon Sep 17 00:00:00 2001 From: FailedProxy Date: Thu, 9 Apr 2026 17:20:09 -0400 Subject: [PATCH] added notify to all needed in unraid essentials --- Orchestrators/daily_sync.sh | 43 ++++--- Rsync/git_pull_execute.sh | 134 ---------------------- Rsync/rsync.sh | 60 +++++----- git_pull_execute.sh | 134 ++++++++++++++++++++++ unRAID_Essentials/clear_logs.sh | 21 ++-- unRAID_Essentials/docker_syslog_filter.sh | 13 ++- unRAID_Essentials/mover-stop.sh | 4 +- unRAID_Essentials/php_fpm_max_children.sh | 36 +++--- unRAID_Essentials/rsync_stop.sh | 9 +- unRAID_Essentials/user_scripts_stop.sh | 3 +- user_script_pluin.sh | 2 +- 11 files changed, 249 insertions(+), 210 deletions(-) delete mode 100644 Rsync/git_pull_execute.sh create mode 100644 git_pull_execute.sh diff --git a/Orchestrators/daily_sync.sh b/Orchestrators/daily_sync.sh index 0a530ea..6d34bbd 100644 --- a/Orchestrators/daily_sync.sh +++ b/Orchestrators/daily_sync.sh @@ -6,34 +6,34 @@ # Per-share rsync handled by rsync.sh — this script tracks pass/fail and total time only. # Add or remove shares in Master.conf under DAILY_SYNC_SHARES. # ----------------------------------------------------------------------------------------------- - + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - + source "$SCRIPT_DIR/../Master.conf" source "$SCRIPT_DIR/../common.sh" - + RSYNC_SCRIPT="$SCRIPT_DIR/../Rsync/rsync.sh" - + # ----------------------------------------------------------------------------------------------- # ━━━ $ICON_GEAR Setup ━━━ # ----------------------------------------------------------------------------------------------- echo "" echo "━━━ $ICON_GEAR Setup ━━━" - + detect_hosts resolve_remote_ip - + # ----------------------------------------------------------------------------------------------- # ━━━ $ICON_SHIELD Pre-flight Checks ━━━ # ----------------------------------------------------------------------------------------------- echo "" echo "━━━ $ICON_SHIELD Pre-flight Checks ━━━" - + # Single connectivity and rootfs check upfront — fail fast before attempting all shares # Individual share and disk checks run per-share inside rsync.sh check_connectivity check_remote_rootfs - + # ----------------------------------------------------------------------------------------------- # Tracking # ----------------------------------------------------------------------------------------------- @@ -42,7 +42,7 @@ FAIL=() SHARE_TIMES=() TOTAL_START=$(date +%s) SHARE_COUNT=${#DAILY_SYNC_SHARES[@]} - + # ----------------------------------------------------------------------------------------------- # ━━━ $ICON_SYNC Transfer ━━━ # ----------------------------------------------------------------------------------------------- @@ -50,16 +50,16 @@ echo "" echo "━━━ $ICON_SYNC Daily Sync Starting — $(date '+%Y-%m-%d %H:%M:%S') ━━━" echo "$ICON_SUMMARY Shares: $SHARE_COUNT" echo "" - + SHARE_INDEX=0 - + for SHARE in "${DAILY_SYNC_SHARES[@]}"; do SHARE_INDEX=$((SHARE_INDEX + 1)) SHARE_NAME=$(basename "$SHARE") SHARE_START=$(date +%s) - + echo "━━━ $ICON_SYNC Share $SHARE_INDEX of $SHARE_COUNT: $SHARE_NAME ━━━" - + if bash "$RSYNC_SCRIPT" "$SHARE"; then SHARE_END=$(date +%s) SHARE_TIMES+=("$SHARE_NAME:$((SHARE_END - SHARE_START))") @@ -71,13 +71,13 @@ for SHARE in "${DAILY_SYNC_SHARES[@]}"; do FAIL+=("$SHARE_NAME") error "$SHARE_NAME failed — continuing to next share" fi - + echo "" done - + TOTAL_END=$(date +%s) TOTAL_DURATION=$((TOTAL_END - TOTAL_START)) - + # ----------------------------------------------------------------------------------------------- # ━━━ $ICON_SUMMARY Summary ━━━ # ----------------------------------------------------------------------------------------------- @@ -99,6 +99,11 @@ echo " $ICON_SUCCESS Passed: ${#PASS[@]}/$SHARE_COUNT" echo " $ICON_ERROR Failed: ${#FAIL[@]}/$SHARE_COUNT" echo " $ICON_TIME Duration: $(format_duration $TOTAL_DURATION)" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" - -[[ ${#FAIL[@]} -gt 0 ]] && exit 1 -exit 0 \ No newline at end of file + +if [[ ${#FAIL[@]} -gt 0 ]]; then + notify "Daily sync completed with failures — ${#FAIL[@]}/$SHARE_COUNT failed: ${FAIL[*]}" "Daily Sync" "warning" + exit 1 +else + notify "Daily sync complete — ${#PASS[@]}/$SHARE_COUNT shares in $(format_duration $TOTAL_DURATION)" "Daily Sync" "normal" + exit 0 +fi \ No newline at end of file diff --git a/Rsync/git_pull_execute.sh b/Rsync/git_pull_execute.sh deleted file mode 100644 index d945a92..0000000 --- a/Rsync/git_pull_execute.sh +++ /dev/null @@ -1,134 +0,0 @@ -#!/bin/bash -# ----------------------------------------------------------------------------------------------- -# --------------------------------- Git Pull & Execute Script ----------------------------------- -# ----------------------------------------------------------------------------------------------- -# Pulls latest scripts from Gitea repo via SSH. -# Uses GITEA_SSH_KEY and SSH_PORT from Master.conf. -# Supports --dry-run, --log, --status flags via common.sh parse_args. -# ----------------------------------------------------------------------------------------------- - -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 " $ICON_SUMMARY GIT SYNC STATUS" - echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" - echo " $ICON_GEAR Repo: $REPO_SSH" - echo " $ICON_GEAR Target: $TARGET_DIR" - echo " $ICON_GEAR SSH Key: $GITEA_SSH_KEY" - echo " $ICON_GEAR SSH Port: $SSH_PORT" - echo " $ICON_INFO Dry Run: $DRY_RUN" - echo " $ICON_INFO Logging: $ENABLE_LOGGING" - echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" - exit 0 -fi - -# ----------------------------------------------------------------------------------------------- -# VALIDATION -# ----------------------------------------------------------------------------------------------- -require_var REPO_SSH -require_var TARGET_DIR -require_var GITEA_SSH_KEY -require_var SSH_PORT - -# ----------------------------------------------------------------------------------------------- -# HEADER -# ----------------------------------------------------------------------------------------------- -echo -echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -echo " $ICON_RUN GIT SYNC STARTING" -echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -info "$ICON_GEAR Repo: $REPO_SSH" -info "$ICON_GEAR Target: $TARGET_DIR" -info "$ICON_INFO Dry Run: $DRY_RUN" -echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" - -log "Repo: $REPO_SSH" -log "Target: $TARGET_DIR" - -# ----------------------------------------------------------------------------------------------- -# DRY RUN -# ----------------------------------------------------------------------------------------------- -if [[ "$DRY_RUN" == true ]]; then - echo - warn "Dry-run enabled — no changes will be made" - info "Would sync: $REPO_SSH" - info "Would target: $TARGET_DIR" - echo - echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" - echo " $ICON_SUMMARY GIT SYNC SUMMARY" - echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" - echo " $ICON_GEAR Repo: $REPO_SSH" - echo " $ICON_GEAR Target: $TARGET_DIR" - echo " $ICON_WARN Status: DRY RUN" - echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" - exit 0 -fi - -# ----------------------------------------------------------------------------------------------- -# MAIN EXECUTION -# ----------------------------------------------------------------------------------------------- -START_TIME=$(date +%s) - -mkdir -p "$TARGET_DIR" -cd "$TARGET_DIR" - -if [[ -d ".git" ]]; then - info "$ICON_SYNC Existing repository detected — updating" - log "git reset --hard" - git reset --hard - - log "git clean -fd" - git clean -fd - - info "$ICON_RUN Pulling latest changes..." - if GIT_SSH_COMMAND="ssh -i $GITEA_SSH_KEY -p $SSH_PORT" git pull; then - success "Git pull successful" - else - error "Git pull failed" - exit 1 - fi - -else - info "$ICON_SYNC No repository found — cloning" - if GIT_SSH_COMMAND="ssh -i $GITEA_SSH_KEY -p $SSH_PORT" git clone "$REPO_SSH" .; then - success "Clone successful" - else - error "Clone failed" - exit 1 - fi -fi - -# ----------------------------------------------------------------------------------------------- -# PERMISSIONS -# ----------------------------------------------------------------------------------------------- -info "$ICON_GEAR Setting executable permissions..." -find "$TARGET_DIR" -type f -name "*.sh" -exec chmod +x {} \; -success "Permissions applied" - -# ----------------------------------------------------------------------------------------------- -# SUMMARY -# ----------------------------------------------------------------------------------------------- -END_TIME=$(date +%s) -DURATION=$((END_TIME - START_TIME)) - -echo -echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -echo " $ICON_SUMMARY GIT SYNC SUMMARY" -echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -echo " $ICON_GEAR Repo: $REPO_SSH" -echo " $ICON_GEAR Target: $TARGET_DIR" -echo " $ICON_TIME Duration: $(format_duration $DURATION)" -echo " $ICON_SUCCESS Status: SUCCESS" -echo " $ICON_INFO Dry Run: $DRY_RUN" -echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" -success "Repository sync complete" \ No newline at end of file diff --git a/Rsync/rsync.sh b/Rsync/rsync.sh index cc72581..29607db 100644 --- a/Rsync/rsync.sh +++ b/Rsync/rsync.sh @@ -4,50 +4,50 @@ # ---------------------------------------------------------------------------------------------- # ---------------- User Variables, Please adjust in Master.conf as needed ---------------------- # ---------------------------------------------------------------------------------------------- - + SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - + source "$SCRIPT_DIR/../Master.conf" source "$SCRIPT_DIR/../common.sh" - + # ----------------------------------------------------------------------------------------------- # Separate the positional directory argument from flag/key=value args. # Flags and key=value pairs are passed to parse_args — directory is handled here. # ----------------------------------------------------------------------------------------------- DIRECTORY="" RAW_ARGS=() - + for ARG in "$@"; do case "$ARG" in --*|*=*) RAW_ARGS+=("$ARG") ;; *) [[ -z "$DIRECTORY" ]] && DIRECTORY="$ARG" || RAW_ARGS+=("$ARG") ;; esac done - + parse_args "${RAW_ARGS[@]}" - + [[ -z "$DIRECTORY" ]] && error "No directory specified. Usage: rsync.sh [--dry-run] [--log]" && exit 1 - + # ----------------------------------------------------------------------------------------------- # ━━━ $ICON_GEAR Setup ━━━ # ----------------------------------------------------------------------------------------------- echo "" echo "━━━ $ICON_GEAR Setup ━━━" - + detect_hosts resolve_remote_ip - + # ----------------------------------------------------------------------------------------------- # ━━━ $ICON_SHIELD Pre-flight Checks ━━━ # ----------------------------------------------------------------------------------------------- echo "" echo "━━━ $ICON_SHIELD Pre-flight Checks ━━━" - + check_connectivity check_remote_rootfs check_remote_share "$DIRECTORY" check_remote_disks "$DIRECTORY" - + # ----------------------------------------------------------------------------------------------- # Profile is inferred from the directory basename (lowercased) # e.g. /mnt/user/appdata-Failover/Arrs_Stack → arrs_stack @@ -55,28 +55,28 @@ check_remote_disks "$DIRECTORY" echo "" PROFILE_NAME=$(basename "$DIRECTORY" | tr '[:upper:]' '[:lower:]') info "$ICON_GEAR Loading profile: $PROFILE_NAME" - + # Scalar overrides — use profile value if defined, fall back to global default BW_LIMIT=${PROFILE_BW_LIMIT[$PROFILE_NAME]:-$BW_LIMIT} RETRY_COUNT=${PROFILE_RETRY_COUNT[$PROFILE_NAME]:-$RETRY_COUNT} SLEEP=${PROFILE_SLEEP[$PROFILE_NAME]:-$SLEEP} CONTAINER_DELAY=${PROFILE_CONTAINER_DELAY[$PROFILE_NAME]:-$CONTAINER_DELAY} - + # Array overrides — profile strings must be converted to bash arrays before use read -r -a CRITICAL_CONTAINER_NAMES <<< "${PROFILE_CRITICAL_CONTAINER_NAMES[$PROFILE_NAME]:-}" read -r -a DELAYED_CONTAINERS <<< "${PROFILE_DELAYED_CONTAINERS[$PROFILE_NAME]:-}" read -r -a EXCLUDE_DIRS <<< "${PROFILE_EXCLUDE_DIRS[$PROFILE_NAME]:-}" - + [[ "$SHOW_STATUS" == true ]] && show_status && exit 0 - + # ----------------------------------------------------------------------------------------------- # ━━━ $ICON_STOP $ICON_CONTAINERS Containers ━━━ # ----------------------------------------------------------------------------------------------- echo "" echo "━━━ $ICON_STOP $ICON_CONTAINERS Containers ━━━" - + stop_containers - + # ----------------------------------------------------------------------------------------------- # ━━━ $ICON_SYNC Transfer ━━━ # ----------------------------------------------------------------------------------------------- @@ -86,22 +86,22 @@ echo "$ICON_RUN Source: $DIRECTORY" echo "$ICON_NET Remote: $REMOTE_SERVER:$DIRECTORY" echo "$ICON_GEAR Profile: $PROFILE_NAME" echo "" - + get_rsync_opts - + # Append profile excludes to rsync options for ex in "${EXCLUDE_DIRS[@]}"; do [[ -n "$ex" ]] && RSYNC_OPTS+=(--exclude="$ex") done - + [[ "$DRY_RUN" == true ]] && RSYNC_OPTS+=("--dry-run") && warn "DRY RUN — no changes will be made" - + START=$(date +%s) RSYNC_SUCCESS=false - + for i in $(seq 1 "$RETRY_COUNT"); do info "$ICON_RETRY Attempt $i of $RETRY_COUNT..." - + # dirname "$DIRECTORY" is intentional — rsync places the directory itself on the remote # e.g. source /mnt/user/Movies syncs to remote /mnt/user/Movies (not /mnt/user/Movies/Movies) if rsync "${RSYNC_OPTS[@]}" \ @@ -115,19 +115,19 @@ for i in $(seq 1 "$RETRY_COUNT"); do [[ "$i" -lt "$RETRY_COUNT" ]] && info "Retrying in ${SLEEP}s..." && sleep "$SLEEP" fi done - + # ----------------------------------------------------------------------------------------------- # ━━━ $ICON_START $ICON_CONTAINERS Containers ━━━ # ----------------------------------------------------------------------------------------------- echo "" echo "━━━ $ICON_START $ICON_CONTAINERS Containers ━━━" - + start_containers - + END=$(date +%s) - + # ----------------------------------------------------------------------------------------------- -# ━━━ $ICON_SUMMARY Summary ━━━ +# ━━━ Summary ━━━ # ----------------------------------------------------------------------------------------------- echo "" echo "━━━━━ $ICON_SUMMARY SUMMARY ━━━━━" @@ -136,10 +136,12 @@ echo "$ICON_GEAR Profile: $PROFILE_NAME" echo "$ICON_TIME Duration: $(format_duration $((END - START)))" if [[ "$RSYNC_SUCCESS" == true ]]; then echo "$ICON_DONE Status: $ICON_SUCCESS DONE" + notify "Rsync complete — $DIRECTORY ($PROFILE_NAME) in $(format_duration $((END - START)))" "Rsync" "normal" else echo "$ICON_ERROR Status: $ICON_ERROR FAILED after $RETRY_COUNT attempts" + notify "Rsync failed — $DIRECTORY ($PROFILE_NAME) after $RETRY_COUNT attempts" "Rsync" "warning" fi echo "━━━━━━━━━━━━━━━━━━━━━━━" - + [[ "$RSYNC_SUCCESS" == false ]] && exit 1 exit 0 \ No newline at end of file diff --git a/git_pull_execute.sh b/git_pull_execute.sh new file mode 100644 index 0000000..ac5fd80 --- /dev/null +++ b/git_pull_execute.sh @@ -0,0 +1,134 @@ +#!/bin/bash +# ----------------------------------------------------------------------------------------------- +# --------------------------------- Git Pull & Execute Script ----------------------------------- +# ----------------------------------------------------------------------------------------------- +# Pulls latest scripts from Gitea repo via SSH and sets executable permissions. +# Lives at the repo root — sources Master.conf and common.sh from the same directory. +# Uses GITEA_SSH_KEY, SSH_PORT and REPO_SSH from Master.conf. +# Supports --dry-run, --log, --status flags via common.sh parse_args. +# ----------------------------------------------------------------------------------------------- + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +# Root level script — sources from same directory, not parent +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 +require_var REPO_SSH +require_var TARGET_DIR +require_var GITEA_SSH_KEY +require_var SSH_PORT + +# ----------------------------------------------------------------------------------------------- +# ━━━ $ICON_SUMMARY Status ━━━ +# ----------------------------------------------------------------------------------------------- +if [[ "$SHOW_STATUS" == true ]]; then + echo "" + echo "━━━━━ $ICON_SUMMARY STATUS ━━━━━" + echo "$ICON_NET Repo: $REPO_SSH" + echo "$ICON_GEAR Target: $TARGET_DIR" + echo "$ICON_GEAR SSH Key: $GITEA_SSH_KEY" + echo "$ICON_GEAR SSH Port: $SSH_PORT" + echo "$ICON_NOTIFY Notifications: unRAID=${NOTIFY_UNRAID:-false} Discord=$([[ -n "${DISCORD_WEBHOOK:-}" ]] && echo enabled || echo disabled)" + echo "$ICON_GEAR Dry Run: $DRY_RUN" + echo "━━━━━━━━━━━━━━━━━━━━━━━" + exit 0 +fi + +[[ "$DRY_RUN" == true ]] && warn "DRY RUN — no changes will be made" + +# ----------------------------------------------------------------------------------------------- +# ━━━ $ICON_SYNC Git Sync ━━━ +# ----------------------------------------------------------------------------------------------- +echo "" +echo "━━━ $ICON_SYNC Git Sync ━━━" +echo "$ICON_NET Repo: $REPO_SSH" +echo "$ICON_GEAR Target: $TARGET_DIR" +echo "" + +START=$(date +%s) +SYNC_SUCCESS=false + +if [[ "$DRY_RUN" == true ]]; then + warn "DRY RUN — would sync $REPO_SSH → $TARGET_DIR" + SYNC_SUCCESS=true +else + mkdir -p "$TARGET_DIR" + cd "$TARGET_DIR" || { error "Cannot cd into $TARGET_DIR"; exit 1; } + + if [[ -d ".git" ]]; then + info "$ICON_SYNC Existing repository detected — updating" + log "git reset --hard" + git reset --hard + + log "git clean -fd" + git clean -fd + + info "Pulling latest changes..." + if GIT_SSH_COMMAND="ssh -i $GITEA_SSH_KEY -p $SSH_PORT" git pull; then + success "Git pull successful" + SYNC_SUCCESS=true + else + error "Git pull failed" + notify "Git pull failed on $(hostname) — check Gitea connectivity" "Git Sync" "alert" + exit 1 + fi + + else + info "$ICON_SYNC No repository found — cloning" + if GIT_SSH_COMMAND="ssh -i $GITEA_SSH_KEY -p $SSH_PORT" git clone "$REPO_SSH" .; then + success "Clone successful" + SYNC_SUCCESS=true + else + error "Clone failed" + notify "Git clone failed on $(hostname) — check Gitea connectivity" "Git Sync" "alert" + exit 1 + fi + fi + + # ----------------------------------------------------------------------------------------------- + # ━━━ $ICON_GEAR Permissions ━━━ + # ----------------------------------------------------------------------------------------------- + echo "" + echo "━━━ $ICON_GEAR Permissions ━━━" + info "Setting executable permissions on all .sh files..." + find "$TARGET_DIR" -type f -name "*.sh" -exec chmod +x {} \; + success "Permissions applied" +fi + +END=$(date +%s) + +# ----------------------------------------------------------------------------------------------- +# ━━━ $ICON_SUMMARY Summary ━━━ +# ----------------------------------------------------------------------------------------------- +echo "" +echo "━━━━━ $ICON_SUMMARY GIT SYNC SUMMARY ━━━━━" +echo "$ICON_NET Repo: $REPO_SSH" +echo "$ICON_GEAR Target: $TARGET_DIR" +echo "$ICON_TIME Duration: $(format_duration $((END - START)))" +if [[ "$DRY_RUN" == true ]]; then + echo "$ICON_WARN Status: DRY RUN — no changes made" +elif [[ "$SYNC_SUCCESS" == true ]]; then + echo "$ICON_DONE Status: $ICON_SUCCESS DONE" + notify "Repository synced successfully on $(hostname)" "Git Sync" "normal" +else + echo "$ICON_ERROR Status: $ICON_ERROR FAILED" +fi +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" \ No newline at end of file diff --git a/unRAID_Essentials/clear_logs.sh b/unRAID_Essentials/clear_logs.sh index 39981f1..df95d41 100644 --- a/unRAID_Essentials/clear_logs.sh +++ b/unRAID_Essentials/clear_logs.sh @@ -35,7 +35,7 @@ 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_CONTAINERS Docker Logs: /var/lib/docker/containers" echo "$ICON_GEAR Dry Run: $DRY_RUN" echo "━━━━━━━━━━━━━━━━━━━━━━━" exit 0 @@ -67,7 +67,7 @@ clear_file() { # 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" + warn "$ICON_CONTAINERS Docker directory not found — skipping" return fi @@ -75,7 +75,7 @@ clear_docker_logs() { 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" + warn "$ICON_CONTAINERS No Docker logs found — skipping" return fi @@ -95,20 +95,21 @@ clear_docker_logs() { echo "" echo "━━━ $ICON_HEALTH Clear Logs ━━━" echo "$ICON_HEALTH System Logs: ${LOG_FILES[*]}" -echo "$ICON_DOCKER Docker Logs: enabled" +echo "$ICON_CONTAINERS 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) +CLEAR_FAILED=false for logfile in "${LOG_FILES[@]}"; do - clear_file "$logfile" + clear_file "$logfile" || CLEAR_FAILED=true done echo "" -echo "━━━ $ICON_DOCKER Docker ━━━" +echo "━━━ $ICON_CONTAINERS Docker ━━━" clear_docker_logs END=$(date +%s) @@ -119,11 +120,15 @@ END=$(date +%s) 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_CONTAINERS 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" +elif [[ "$CLEAR_FAILED" == true ]]; then + echo "$ICON_ERROR Status: $ICON_ERROR SOME LOGS FAILED TO CLEAR" + notify "Log clear completed with errors on $(hostname)" "Clear Logs" "warning" else echo "$ICON_DONE Status: $ICON_SUCCESS DONE" + notify "Logs cleared successfully on $(hostname)" "Clear Logs" "normal" fi -echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" \ No newline at end of file +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" \ No newline at end of file diff --git a/unRAID_Essentials/docker_syslog_filter.sh b/unRAID_Essentials/docker_syslog_filter.sh index 1db45a5..650fd01 100644 --- a/unRAID_Essentials/docker_syslog_filter.sh +++ b/unRAID_Essentials/docker_syslog_filter.sh @@ -70,16 +70,17 @@ EOF restart_rsyslog() { if [[ "$DRY_RUN" == true ]]; then warn "DRY RUN — would restart rsyslog service" - return + return 0 fi info "Restarting rsyslog..." if /etc/rc.d/rc.rsyslogd restart; then success "rsyslog restarted" + return 0 else error "Failed to restart rsyslog" - exit 1 + return 1 fi } @@ -98,7 +99,9 @@ echo "" START=$(date +%s) create_filter -restart_rsyslog + +RSYSLOG_OK=true +restart_rsyslog || RSYSLOG_OK=false END=$(date +%s) @@ -112,7 +115,11 @@ 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" +elif [[ "$RSYSLOG_OK" == false ]]; then + echo "$ICON_ERROR Status: $ICON_ERROR RSYSLOG RESTART FAILED" + notify "rsyslog restart failed on $(hostname) — syslog filter may not be active" "Syslog Filter" "warning" else echo "$ICON_DONE Status: $ICON_SUCCESS DONE" + notify "Syslog filter applied on $(hostname)" "Syslog Filter" "normal" fi echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" \ No newline at end of file diff --git a/unRAID_Essentials/mover-stop.sh b/unRAID_Essentials/mover-stop.sh index a55645d..e25a894 100644 --- a/unRAID_Essentials/mover-stop.sh +++ b/unRAID_Essentials/mover-stop.sh @@ -108,7 +108,9 @@ 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" + notify "Mover stop failed — mover still running on $(hostname)" "Mover Stop" "warning" else echo "$ICON_DONE Status: $ICON_SUCCESS STOPPED / NOT RUNNING" + notify "Mover stopped on $(hostname)" "Mover Stop" "normal" fi -echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" \ No newline at end of file +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" \ No newline at end of file diff --git a/unRAID_Essentials/php_fpm_max_children.sh b/unRAID_Essentials/php_fpm_max_children.sh index c2591e4..7dcc802 100644 --- a/unRAID_Essentials/php_fpm_max_children.sh +++ b/unRAID_Essentials/php_fpm_max_children.sh @@ -58,33 +58,33 @@ apply_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 + return 0 fi # Verify config file exists before attempting changes if [[ ! -f "$PHP_CONF" ]]; then error "PHP config file not found: $PHP_CONF" - exit 1 + return 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 + if ! sed -i "s/^pm\.max_children.*/$target/" "$PHP_CONF"; then error "Failed to update PHP config: $PHP_CONF" - exit 1 + return 1 fi + success "Config updated" + info "Restarting PHP-FPM..." - if /etc/rc.d/rc.php-fpm restart; then - success "PHP-FPM restarted" - else + if ! /etc/rc.d/rc.php-fpm restart; then error "PHP-FPM restart failed" - exit 1 + return 1 fi + success "PHP-FPM restarted" + # Verify the value was applied correctly local current current=$(grep -E "^pm\.max_children" "$PHP_CONF" || true) @@ -95,6 +95,8 @@ apply_php_max_children() { else warn "Could not verify configuration value — check $PHP_CONF manually" fi + + return 0 } # ----------------------------------------------------------------------------------------------- @@ -111,7 +113,8 @@ echo "" START=$(date +%s) -apply_php_max_children +PHP_SUCCESS=false +apply_php_max_children && PHP_SUCCESS=true END=$(date +%s) @@ -125,7 +128,14 @@ 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 +elif [[ "$PHP_SUCCESS" == true ]]; then echo "$ICON_DONE Status: $ICON_SUCCESS DONE" + notify "PHP-FPM max_children set to $PHP_MAX_CHILDREN on $(hostname)" "PHP-FPM" "normal" +else + echo "$ICON_ERROR Status: $ICON_ERROR FAILED" + notify "PHP-FPM config update failed on $(hostname)" "PHP-FPM" "warning" fi -echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" \ No newline at end of file +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + +[[ "$PHP_SUCCESS" == false ]] && exit 1 +exit 0 \ No newline at end of file diff --git a/unRAID_Essentials/rsync_stop.sh b/unRAID_Essentials/rsync_stop.sh index af6a989..2a6745f 100644 --- a/unRAID_Essentials/rsync_stop.sh +++ b/unRAID_Essentials/rsync_stop.sh @@ -189,4 +189,11 @@ elif [[ "$LOCAL_KILLED" == true ]]; then fi echo "$ICON_TIME Dry Run: $DRY_RUN" -echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" \ No newline at end of file +echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" + +# Notify based on what happened +if [[ "$LOCAL_KILLED" == true ]] || [[ "$REMOTE_KILLED" == true ]]; then + local_status=$([[ "$LOCAL_KILLED" == true ]] && echo "killed" || echo "clean") + remote_status=$([[ "$REMOTE_KILLED" == true ]] && echo "killed" || echo "clean") + notify "Rsync stopped — local: $local_status remote: $remote_status — ${#CONTAINERS_RESTARTED[@]} containers recovered" "Rsync Stop" "warning" +fi \ No newline at end of file diff --git a/unRAID_Essentials/user_scripts_stop.sh b/unRAID_Essentials/user_scripts_stop.sh index 5339dff..4de8ece 100644 --- a/unRAID_Essentials/user_scripts_stop.sh +++ b/unRAID_Essentials/user_scripts_stop.sh @@ -52,7 +52,6 @@ get_user_script_pids() { # 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) @@ -117,8 +116,10 @@ else REMAINING=$(get_user_script_pids) if [[ -z "$REMAINING" ]]; then echo "$ICON_DONE Status: $ICON_SUCCESS ALL PROCESSES STOPPED" + notify "User Scripts stopped on $(hostname)" "User Script Stop" "warning" else echo "$ICON_WARN Status: $ICON_WARN SOME PROCESSES MAY STILL BE RUNNING" + notify "User Script stop completed but some processes may still be running on $(hostname)" "User Script Stop" "warning" fi fi diff --git a/user_script_pluin.sh b/user_script_pluin.sh index 74a10e6..67bfc06 100644 --- a/user_script_pluin.sh +++ b/user_script_pluin.sh @@ -74,7 +74,7 @@ # no concurrency needed, bandwidth limiting keeps things sane if appdata jobs overlap. # # This is where 80% of your rsync shares should live. Only create individual scheduled -# entries for shares that need their own timing — like appdata profiles above. +# entries for shares that need their own timing — like appdata profiles below. # # ━━━ Orchestrators ━━━ #/mnt/user/appdata/unraid_scripts/Orchestrators/daily_sync.sh