#!/bin/bash # ============================================================================================== # ================================= User Script Template ======================================= # ============================================================================================== # # This file is the master template for all scripts run via the unRAID User Scripts plugin. # Copy and paste the contents of this file into a new User Script entry in the plugin, # then uncomment the script you want to run and set your schedule. # # All scripts live at: /mnt/user/appdata/unraid_scripts/ # All configuration at: /mnt/user/appdata/unraid_scripts/Master.conf # Shared functions at: /mnt/user/appdata/unraid_scripts/common.sh # # ============================================================================================== # Changelog: # v1.0 — Initial template # v1.1 — MAX_RSYNC_PROCS removed, --status flag, full directory tree, changelog # v1.2 — Docker Essentials, Media, Transcodes, System Watchdog added # v1.3 — Failover script added # v1.4 — WebGUI watchdog, ZFS snapshot, Docker network connect, schedules section # v1.5 — media_management.sh orchestrator, corrected filenames, git repo section # v1.6 — lidarr_cleanup.sh, sonarr_cleanup.sh, radarr_cleanup.sh added # v1.7 — cert_monitor.sh added # v1.8 — Monitor/ folder added with all monitoring scripts # cert_monitor.sh moved from unRAID_Essentials to Monitor/ # backup_verify.sh, smart_health.sh, bandwidth_monitor.sh added # weekly_health_digest.sh, emby_session_report.sh added # ZFS memory snapshot moved to Monitor/ — informational only # Directory tree updated to reflect full ecosystem # ============================================================================================== # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # ━━━ 📂 Repository Structure ━━━ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # # /mnt/user/appdata/unraid_scripts/ # ├── Master.conf # All user configuration — edit this file only # ├── common.sh # Shared library — functions used by all scripts # ├── README.md # Project overview and quick start # ├── User_Script_Template.sh # This file — copy into User Scripts plugin # ├── git_pull_execute.sh # Pulls latest scripts from Gitea repo # │ # ├── Failover/ # │ └── failover.sh # Mutual container failover — runs continuously # │ # ├── Monitor/ # │ ├── backup_verify.sh # Random sample checksum verification vs remote # │ ├── cert_monitor.sh # SSL certificate expiry — direct openssl check # │ ├── emby_session_report.sh # Weekly Emby usage statistics via API # │ ├── smart_health.sh # Drive SMART attribute monitoring # │ ├── bandwidth_monitor.sh # Daily transfer logging + weekly summary # │ ├── weekly_health_digest.sh # Aggregated system health — always/smart/weekly # │ └── zfs_memory_snapshot.sh # Weekly ZFS health and memory diagnostic report # │ # ├── Orchestrators/ # │ ├── daily_sync.sh # Runs all daily media share syncs sequentially # │ └── media_management.sh # Runs permissions + cleaners + arr cleanup sequentially # │ # ├── Rsync/ # │ ├── rsync.sh # Core rsync script — called per share or profile # │ └── README_Rsync_Setup.md # Rsync-specific setup guide # │ # ├── Docker_Essentials/ # │ ├── docker_watchdog.sh # Container health monitor — memory, CPU, HTTP, stops # │ ├── docker_daily_restart.sh # Restarts configured containers daily # │ ├── docker_weekly_restart.sh # Restarts configured containers weekly # │ └── docker_network_connect.sh # Connects containers to extra networks on boot # │ # ├── Media/ # │ ├── media_shares_permissions.sh # Applies permissions to all media shares # │ ├── media_cleaner.sh # Removes junk files — profiles: anime, media # │ ├── lidarr_cleanup.sh # Removes orphaned music files via Lidarr API # │ ├── sonarr_cleanup.sh # Removes orphaned TV files via Sonarr API # │ └── radarr_cleanup.sh # Removes orphaned movie files via Radarr API # │ # ├── Transcodes/ # │ ├── ramdisk_setup.sh # Creates ramdisk and transcode symlink # │ ├── transcode_manager.sh # Monitors ramdisk usage, manages symlink # │ └── transcode_cleanup.sh # Removes old inactive transcode files # │ # ├── Tools/ # │ └── recreate_shares.sh # Recreates share dirs from .cfg files after incident # │ # └── unRAID_Essentials/ # ├── clear_logs.sh # Clears unRAID system and Docker log files # ├── docker_syslog_filter.sh # Filters Docker veth noise from syslog # ├── mover_stop.sh # Safely stops the unRAID mover # ├── php_fpm_max_children.sh # Sets PHP-FPM max children value # ├── rsync_stop.sh # Stops all rsync processes on both servers # ├── server_reboot.sh # Graceful server reboot with user warning # ├── system_watchdog.sh # System health monitor — last line of defense # ├── user_scripts_stop.sh # Stops running User Scripts plugin jobs # └── webgui_restart.sh # WebGUI watchdog — nginx + emhttp restart # # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # ━━━ 🚀 Script Commands — Uncomment the one you want to run ━━━ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # # ━━━ Failover (README) ━━━ # Runs continuously as background task — set "At Startup of Array" as background task. # Both servers must have this running for mutual failover to work. # #/mnt/user/appdata/unraid_scripts/Failover/failover.sh # # ━━━ Monitor ━━━ #/mnt/user/appdata/unraid_scripts/Monitor/backup_verify.sh #/mnt/user/appdata/unraid_scripts/Monitor/cert_monitor.sh #/mnt/user/appdata/unraid_scripts/Monitor/emby_session_report.sh #/mnt/user/appdata/unraid_scripts/Monitor/smart_health.sh #/mnt/user/appdata/unraid_scripts/Monitor/bandwidth_monitor.sh #/mnt/user/appdata/unraid_scripts/Monitor/weekly_health_digest.sh #/mnt/user/appdata/unraid_scripts/Monitor/zfs_memory_snapshot.sh # # ━━━ Orchestrators ━━━ #/mnt/user/appdata/unraid_scripts/Orchestrators/daily_sync.sh #/mnt/user/appdata/unraid_scripts/Orchestrators/media_management.sh # # ━━━ Rsync — Appdata Profiles ━━━ #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-Failover/Arrs_Stack #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-Failover/Critical-Data #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-Failover/Important-Data #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-Failover/Emby #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/appdata-Failover/Gmer4Lfe # # ━━━ Rsync — Individual Media Shares (ad hoc) ━━━ #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Movies #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Tv_Shows #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Anime_Shows #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Anime_Shows-Old #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Anime_Movies #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Anime_Movies-Old #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Books #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Intros #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Kids_Movies #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Kids_Tv_Shows #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Music_Videos #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/Nextcloud #/mnt/user/appdata/unraid_scripts/Rsync/rsync.sh /mnt/user/stand-up_comedy # # ━━━ Docker Essentials ━━━ #/mnt/user/appdata/unraid_scripts/Docker_Essentials/docker_watchdog.sh #/mnt/user/appdata/unraid_scripts/Docker_Essentials/docker_daily_restart.sh #/mnt/user/appdata/unraid_scripts/Docker_Essentials/docker_weekly_restart.sh #/mnt/user/appdata/unraid_scripts/Docker_Essentials/docker_network_connect.sh # # ━━━ Transcodes ━━━ #/mnt/user/appdata/unraid_scripts/Transcodes/ramdisk_setup.sh #/mnt/user/appdata/unraid_scripts/Transcodes/transcode_manager.sh #/mnt/user/appdata/unraid_scripts/Transcodes/transcode_cleanup.sh # # ━━━ Tools ━━━ #/mnt/user/appdata/unraid_scripts/Tools/recreate_shares.sh # # ━━━ unRAID Essentials ━━━ #/mnt/user/appdata/unraid_scripts/unRAID_Essentials/clear_logs.sh #/mnt/user/appdata/unraid_scripts/unRAID_Essentials/docker_syslog_filter.sh #/mnt/user/appdata/unraid_scripts/unRAID_Essentials/mover_stop.sh #/mnt/user/appdata/unraid_scripts/unRAID_Essentials/php_fpm_max_children.sh #/mnt/user/appdata/unraid_scripts/unRAID_Essentials/rsync_stop.sh #/mnt/user/appdata/unraid_scripts/unRAID_Essentials/server_reboot.sh #/mnt/user/appdata/unraid_scripts/unRAID_Essentials/system_watchdog.sh #/mnt/user/appdata/unraid_scripts/unRAID_Essentials/user_scripts_stop.sh #/mnt/user/appdata/unraid_scripts/unRAID_Essentials/webgui_restart.sh # # ━━━ Git repo (Gitea) ━━━ #/mnt/user/appdata/unraid_scripts/git_pull_execute.sh # # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # ━━━ ⚙️ Arguments ━━━ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # # --dry-run Preview what would happen — no changes made # --log Enable verbose logging output # --no-log Disable logging (overrides Master.conf) # --status Print resolved config and current state then exit # --help Show usage information # KEY=VALUE Override any Master.conf variable for this run only # # ━━━ Special arguments ━━━ # failover.sh --status — check current state without restarting loop # failover.sh --dry-run --log — test logic without touching containers # media_cleaner.sh anime --dry-run — profile required as first argument # bandwidth_monitor.sh --report — generate weekly summary report # lidarr/sonarr/radarr --dry-run --log — always test arr cleanup first # # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # ━━━ 📋 Recommended Schedules ━━━ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ # # ━━━ At Startup of Array ━━━ # failover.sh — background task # ramdisk_setup.sh # docker_network_connect.sh # docker_syslog_filter.sh # php_fpm_max_children.sh # # ━━━ Frequent (every few minutes) ━━━ # */3 * * * * transcode_manager.sh # */5 * * * * transcode_cleanup.sh # */10 * * * * webgui_restart.sh # */15 * * * * docker_watchdog.sh # */15 * * * * system_watchdog.sh # # ━━━ Daily ━━━ # 0 1 * * * daily_sync.sh # 0 2 * * * media_management.sh # 0 3 * * * docker_daily_restart.sh # 0 8 * * * weekly_health_digest.sh (profile controls if it sends) # # ━━━ Weekly — Sunday morning block ━━━ # 0 3 * * 0 docker_weekly_restart.sh # 0 5 * * 0 clear_logs.sh # 0 6 * * 0 zfs_memory_snapshot.sh # 0 7 * * 0 smart_health.sh # 0 8 * * 0 weekly_health_digest.sh (weekly profile sends today) # 0 9 * * 0 cert_monitor.sh # 0 10 * * 0 backup_verify.sh # 0 11 * * 0 emby_session_report.sh # # ━━━ Rsync profiles ━━━ # Schedule individually as needed # # ━━━ Bandwidth monitor ━━━ # bandwidth_monitor.sh --log-transfer is called automatically by rsync.sh # bandwidth_monitor.sh --report runs standalone for weekly summary # # ==============================================================================================