Advertisement
zerg1980

Mover script

Apr 29th, 2025
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.59 KB | Source Code | 0 0
  1. #!/bin/bash
  2.  
  3. # Config
  4. THRESHOLD=70
  5. CACHE_PATH="/mnt/cache"
  6.  
  7. # Get current time in minutes since midnight
  8. CURRENT_MIN=$(date +%H:%M | awk -F: '{ print ($1 * 60) + $2 }')
  9.  
  10. # Define time window: 1:00am to 1:30am = 60 to 90 minutes
  11. RUN_WINDOW_START=60
  12. RUN_WINDOW_END=90
  13.  
  14. # Get current cache usage as integer
  15. USAGE=$(df "$CACHE_PATH" | awk 'NR==2 {gsub("%",""); print $5}')
  16.  
  17. # Determine if we should run the mover
  18. if [ "$CURRENT_MIN" -ge "$RUN_WINDOW_START" ] && [ "$CURRENT_MIN" -lt "$RUN_WINDOW_END" ]; then
  19.     logger "Within 1:00–1:30am window. Running Mover regardless of cache usage."
  20.     SHOULD_RUN=1
  21. elif [ "$USAGE" -ge "$THRESHOLD" ]; then
  22.     logger "Cache usage at ${USAGE}%. Running Mover and pausing containers."
  23.     SHOULD_RUN=1
  24. else
  25.     logger "Cache usage at ${USAGE}%. Outside time window. No action taken."
  26.     SHOULD_RUN=0
  27. fi
  28.  
  29. if [ "$SHOULD_RUN" -eq 1 ]; then
  30.     # Pause containers
  31.     docker pause binhex-sabnzbd
  32.     docker pause binhex-radarr
  33.     docker pause sonarr
  34.  
  35.     # Pause parity (optional)
  36.     if command -v parity.check &> /dev/null; then
  37.         logger "Pausing parity check using Parity Check Tuning plugin..."
  38.         parity.check pause
  39.     fi
  40.    
  41.  
  42.     /usr/local/sbin/mover start
  43.  
  44.     # Wait for disk activity to stop
  45.     sleep 60
  46.  
  47.  
  48.     # Resume parity
  49.     if command -v parity.check &> /dev/null; then
  50.         logger "Resuming parity check..."
  51.         parity.check resume
  52.     fi
  53.  
  54.  
  55.     echo "$(date): Resuming SABnzbd, Radarr and Sonarr"
  56.     docker unpause binhex-sabnzbd
  57.     docker unpause binhex-radarr
  58.     docker unpause sonarr
  59.  
  60. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement