Files
Varaverk/user_script_pluin.sh
T

202 lines
12 KiB
Bash

#!/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 in this ecosystem live at:
# /mnt/user/appdata/unraid_scripts/
#
# Configuration for all scripts is managed in one place:
# /mnt/user/appdata/unraid_scripts/Master.conf
#
# Shared runtime functions used by all scripts:
# /mnt/user/appdata/unraid_scripts/common.sh
#
# ==============================================================================================
# Changelog:
# v1.0 — Initial template
# v1.1 — MAX_RSYNC_PROCS removed — bandwidth limiting handles concurrency
# Typo fixes, --status flag added, full directory tree, changelog added
# v1.2 — Docker Essentials, Media, Transcodes, System Watchdog added
# Directory tree updated to reflect full ecosystem
# v1.3 — Failover script added, directory tree updated with Failover folder
# v1.4 — WebGUI watchdog added
# ZFS memory snapshot added
# Docker network connect added
# 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
# │
# ├── Orchestrators/
# │ └── daily_sync.sh # Runs all daily media share syncs 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_permissions.sh # Applies permissions to all media shares
# │ └── media_cleaner.sh # Removes junk files — profiles: anime, media
# │
# ├── Transcodes/
# │ ├── ramdisk_setup.sh # Creates ramdisk and transcode symlink — run at array start
# │ ├── transcode_manager.sh # Monitors ramdisk usage, manages symlink direction
# │ └── 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_script_stop.sh # Stops running User Scripts plugin jobs
# ├── webgui_restart.sh # WebGUI watchdog — nginx + emhttp escalating restart
# └── zfs_memory_snapshot.sh # Weekly ZFS health and memory diagnostic report
#
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# ━━━ 🚀 Script Commands — Uncomment the one you want to run ━━━
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#
# ━━━ Failover (README) ━━━
# Runs continuously as a background task — do NOT schedule with a time interval.
# Set schedule to "At Startup of Array" — background task.
# Both servers must have this script running for mutual failover to work.
# Use --status to check current state without restarting the loop.
#
# ━━━ Failover ━━━
#/mnt/user/appdata/unraid_scripts/Failover/failover.sh
#
# ━━━ Orchestrators ━━━
#/mnt/user/appdata/unraid_scripts/Orchestrators/daily_sync.sh
#
# ━━━ Rsync — Appdata Profiles (scheduled individually) ━━━
#/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 use) ━━━
#/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
#
# ━━━ Media ━━━
#/mnt/user/appdata/unraid_scripts/Media/media_shares_permissions.sh
#/mnt/user/appdata/unraid_scripts/Media/media_cleaner.sh anime
#/mnt/user/appdata/unraid_scripts/Media/media_cleaner.sh media
#
# ━━━ 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
#/mnt/user/appdata/unraid_scripts/unRAID_Essentials/zfs_memory_snapshot.sh
#
# ━━━ Git repo (Gitea) ━━━
#/mnt/user/appdata/unraid_scripts/git_pull_execute.sh
#
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# ━━━ ⚙️ Arguments — Add after the script path ━━━
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#
# --dry-run Preview what would happen — no changes made
# --log Enable verbose logging output
# --no-log Disable logging (overrides Master.conf setting)
# --status Print resolved configuration and current state then exit
# --help Show usage information
# KEY=VALUE Override any Master.conf variable for this run only
#
# ━━━ Media Cleaner profile (required first argument) ━━━
# media_cleaner.sh anime --dry-run
# media_cleaner.sh media --dry-run
#
# ━━━ Failover specific ━━━
# failover.sh --status — check current state
# failover.sh --dry-run --log — test logic without touching containers
#
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# ━━━ 📋 Recommended Schedules ━━━
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
#
# failover.sh — At Startup of Array (background task)
# ramdisk_setup.sh — At Startup of Array
# docker_network_connect.sh — At Startup of Array
# docker_syslog_filter.sh — At Startup of Array
# php_fpm_max_children.sh — At Startup of Array
#
# transcode_manager.sh — */3 * * * * (every 3 minutes)
# transcode_cleanup.sh — */5 * * * * (every 5 minutes)
# docker_watchdog.sh — */15 * * * * (every 15 minutes)
# webgui_restart.sh — */10 * * * * (every 10 minutes)
# system_watchdog.sh — */15 * * * * (every 15 minutes)
#
# daily_sync.sh — 0 1 * * * (daily at 1am)
# docker_daily_restart.sh — 0 3 * * * (daily at 3am)
# media_cleaner.sh anime — 0 2 * * * (daily at 2am)
# media_cleaner.sh media — 0 2 * * * (daily at 2am)
# media_permissions.sh — 0 4 * * 0 (weekly Sunday 4am)
# clear_logs.sh — 0 5 * * 0 (weekly Sunday 5am)
# zfs_memory_snapshot.sh — 0 6 * * 0 (weekly Sunday 6am)
# docker_weekly_restart.sh — 0 3 * * 0 (weekly Sunday 3am)
#
# rsync.sh profiles — schedule individually as needed
#
# ==============================================================================================