May 10, 20251 yr I have been setting up my first Unraid Server over the last few weeks and keep filling up my cache drive. Found a lot of helpful advice out there. I setup Mover Tuning, got hardlinks working, and returned my 512GB SSD and replaced it with 2TB but that still is not stopping my cache from filling up when I do stupid stuff like download a multi-season show in remux or a collection 4K movies at once. And I don't want to keep waking up and and have to deal with my server being down. The Mover Tuning plugin is great and its "Move All from Primary->Secondary" if above x% is really a key functionality when the cache is filling up. And for traditional cache usage situations, I take advantage of the "age" logic and have new content stay on the cache for a week to seed and get the initial peak of IO from usage and 'arr processing out of the way before transferring to the array for longer term storage. For those 99% / normal situations having the mover run every week is all that I need. If content sticks around on the cache for two weeks instead of one it is no problem as long as there is space on the cache. But weekly won't handle a full cache. I tried moving up the schedule for the mover to run daily and that still wasn't enough to stop a crash, probably because my download client was keeping files locked up and the mover was not able to complete. I didn't want to go to hourly schedule because I would prefer to not have the mover running during the day in "normal" circumstances. So, it was clear that I would need two triggers for the mover, the normal schedule and an "emergency" / "cache full" trigger. I found some different threads out there where people decided to do similar things, but not a complete solution in one place. So I cobbled one together. I am new to script writing so I am sure people can recommend improvements. But this seems to serve my needs well, and I figure others may benefit from it too. Optional Plugins I use in conjunction with this script: "Mover Tuning" and "User Scripts". I keep this script in "User Scripts". What this script does: Should be run frequently, I currently run every 15 minutes (custom cron: */15 * * * *). 99.99% of the time it simply confirms the cache is not full and exits without doing anything. If cache is over the defined threshold it: Confirms this script is not already running Sends a warning notification via Unraid Stops (non-blacklisted) Docker containers Runs the Mover Restarts Docker containers Probably a little more verbose than needed in the script but hopefully it helps people setup / customize to their needs. Credit to Plugin creators and people in threads like this one that did all the real work. I just pasted it together. #!/bin/bash # This script is intended to be run frequently to check if the cache drive is full. # If the cache drive is below the threshold it exits without taking any other action. # If the cache drive is full it stops all Docker Continers and runs the mover. # Set the percent threshold for how full the cache drive is to take action. # IMPORTANT: Make sure Mover will move files if run. Suggest setting "Move All from Primary->Secondary" in Mover Tuning 5% lower than this. pct_threshold="85" lock_file="/tmp/mover_lock" cache_path="/mnt/cache" # Blacklist Docker Containers to not stop / start here Blacklist=( Plex-Media-Server steam-headless ) # List any Docker Containers to be restarted first here StartFirst=( GluetunVPN ) #### Check if cache is below threshold, if true takes no action and exits #### if [[ $(df -h "$cache_path" | awk 'NR==2 {sub(/%/, "", $5); print $5}') -lt "$pct_threshold" ]]; then echo "Cache drive at: " $(df -h "$cache_path" | awk 'NR==2 {sub(/%/, "", $5);print $5}') "% full. Below $pct_threshold% threshold. Taking no action." exit 0 fi echo "Cache drive at: " $(df -h "$cache_path" | awk 'NR==2 {sub(/%/, "", $5);print $5}') "% full! Above $pct_threshold% threshold!" #### Check if the mover is already running #### if [ -f "$lock_file" ]; then echo "Mover already running!" exit 1 fi #### Send Warning #### /usr/local/emhttp/plugins/dynamix/scripts/notify -i warning -s Docker -d "Cache drive is full! Stopping containers and running mover!" #### Touch lock file / prevent script from starting the mover again #### touch "$lock_file" #### Get all Docker Containers #### Containers=$(docker ps -a --format "{{.Names}}") #### Loop thru all containers #### for val in $Containers; do Skip=false #### Skip those in blacklist #### for check in ${Blacklist[@]}; do if [ $val == $check ] then Skip=true fi done #### Stop containers #### if [ $(docker container inspect -f '{{.State.Running}}' $val) == "true" ] && [ $Skip == "false" ] then docker container stop -t 30 $val echo "stopped " $val fi done echo "Stopped all containers (not in blacklist). Running Mover." #### Run Mover #### #### Command to start Mover Tuning: #### /usr/local/emhttp/plugins/ca.mover.tuning/age_mover start #### Command to start OG Mover: #### #mover echo "Mover Done. Starting containers." #### Start the "Start First" containers #### for val in $StartFirst; do Skip=false #### Skip those in blacklist #### for check in ${Blacklist[@]}; do if [ $val == $check ] then Skip=true fi done #### Start containers #### if [ $(docker container inspect -f '{{.State.Running}}' $val) == "false" ] && [ $Skip == "false" ] then docker container start $val echo "started " $val fi done #### Loop thru all containers #### for val in $Containers; do Skip=false #### Skip those in blacklist #### for check in ${Blacklist[@]}; do if [ $val == $check ] then Skip=true fi done #### Start containers #### if [ $(docker container inspect -f '{{.State.Running}}' $val) == "false" ] && [ $Skip == "false" ] then docker container start $val echo "started " $val fi done echo "Started all containers (not in blacklist). Releasing lock file." #### Remove mover lock file #### rm "$lock_file" echo "cacheFull script end" exit 0
May 12, 20251 yr Community Expert nice script. Usually these kind of post are found and located in user customizations. https://forums.unraid.net/forum/12-user-customizations/ there are some interesting and fun script floating around.
May 12, 20251 yr Author 17 hours ago, bmartino1 said: nice script. Usually these kind of post are found and located in user customizations. https://forums.unraid.net/forum/12-user-customizations/ there are some interesting and fun script floating around. Ah, this thread can be moved! Edit: Reposted here: I will try to delete this thread... Edited May 12, 20251 yr by JTVUS Relocation Thread
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.