CLAUDE: Enhance Tdarr system with GPU transcoding optimization and automated maintenance
## Tdarr Plugin Stack Research & Configuration - Research optimal H.265/HEVC plugin stacks for quality-focused transcoding - Configure GPU threshold (95%) to prevent self-termination during transcoding - Add Tdarr exception logic to distinguish transcoding from gaming GPU usage - Update gaming detection to preserve active transcoding jobs ## Automated System Maintenance - Add cron job for automatic cleanup of abandoned Tdarr temp directories - Cleanup runs every 6 hours, preserves active jobs (< 6 hours old) - Prevents /tmp filesystem bloat from interrupted transcoding jobs - Safe cleanup only targets Tdarr-specific work directories ## Enhanced Documentation - Add comprehensive Tdarr automation documentation in scripts/tdarr/README.md - Document cleanup system and its relationship to main scheduler - Update CLAUDE.md with Tdarr keyword triggers and context loading - Add troubleshooting section for both scheduler and cleanup cron jobs ## System Architecture Improvements - Organize Tdarr scripts under dedicated scripts/tdarr/ directory - Maintain backwards compatibility with existing cron jobs - Add gaming-aware scheduling with configurable time windows - Implement robust GPU usage detection with Tdarr transcoding awareness 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
df3d22b218
commit
ccdd7ee8b4
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
.claude/tmp/
|
.claude/tmp/
|
||||||
|
tmp/
|
||||||
11
CLAUDE.md
11
CLAUDE.md
@ -63,9 +63,10 @@ When working in specific directories:
|
|||||||
- Load: `examples/vm-management/`
|
- Load: `examples/vm-management/`
|
||||||
- Load: `reference/vm-management/`
|
- Load: `reference/vm-management/`
|
||||||
|
|
||||||
**Scripts directory (/scripts/)**
|
**Scripts directory (/scripts/, /scripts/*/)**
|
||||||
- Load: `patterns/` (relevant to script type)
|
- Load: `patterns/` (relevant to script type)
|
||||||
- Load: `reference/` (relevant troubleshooting guides)
|
- Load: `reference/` (relevant troubleshooting guides)
|
||||||
|
- Load: `scripts/*/README.md` (subsystem-specific documentation)
|
||||||
- Context: Active operational scripts - treat as production code
|
- Context: Active operational scripts - treat as production code
|
||||||
|
|
||||||
### Keyword Triggers
|
### Keyword Triggers
|
||||||
@ -118,9 +119,11 @@ When user mentions specific terms, automatically load relevant docs:
|
|||||||
- Load: `examples/vm-management/`
|
- Load: `examples/vm-management/`
|
||||||
|
|
||||||
**Tdarr Keywords**
|
**Tdarr Keywords**
|
||||||
- "tdarr", "transcode", "ffmpeg", "gpu transcoding", "nvenc", "forEach error"
|
- "tdarr", "transcode", "ffmpeg", "gpu transcoding", "nvenc", "forEach error", "gaming detection", "scheduler"
|
||||||
- Load: `reference/docker/tdarr-troubleshooting.md`
|
- Load: `reference/docker/tdarr-troubleshooting.md`
|
||||||
- Load: `patterns/docker/distributed-transcoding.md`
|
- Load: `patterns/docker/distributed-transcoding.md`
|
||||||
|
- Load: `scripts/tdarr/README.md` (for automation and scheduling)
|
||||||
|
- Note: Gaming-aware scheduling system with configurable time windows available
|
||||||
|
|
||||||
### Priority Rules
|
### Priority Rules
|
||||||
1. **File extension triggers** take highest priority
|
1. **File extension triggers** take highest priority
|
||||||
@ -143,6 +146,8 @@ When user mentions specific terms, automatically load relevant docs:
|
|||||||
/examples/ # Complete working implementations
|
/examples/ # Complete working implementations
|
||||||
/reference/ # Troubleshooting, cheat sheets, fallback info
|
/reference/ # Troubleshooting, cheat sheets, fallback info
|
||||||
/scripts/ # Active scripts and utilities for home lab operations
|
/scripts/ # Active scripts and utilities for home lab operations
|
||||||
|
├── tdarr/ # Tdarr automation with gaming-aware scheduling
|
||||||
|
└── <future>/ # Other organized automation subsystems
|
||||||
```
|
```
|
||||||
|
|
||||||
Each pattern file should reference relevant examples and reference materials.
|
Each pattern file should reference relevant examples and reference materials.
|
||||||
@ -150,6 +155,8 @@ Each pattern file should reference relevant examples and reference materials.
|
|||||||
### Directory Usage Guidelines
|
### Directory Usage Guidelines
|
||||||
|
|
||||||
- `/scripts/` - Contains actively used scripts for home lab management and operations
|
- `/scripts/` - Contains actively used scripts for home lab management and operations
|
||||||
|
- Organized by subsystem (e.g., `tdarr/`, `networking/`, `vm-management/`)
|
||||||
|
- Each subsystem includes its own README.md with complete documentation
|
||||||
- `/examples/` - Contains example configurations and template scripts for reference
|
- `/examples/` - Contains example configurations and template scripts for reference
|
||||||
- `/patterns/` - Best practices and architectural guidance
|
- `/patterns/` - Best practices and architectural guidance
|
||||||
- `/reference/` - Troubleshooting guides and technical references
|
- `/reference/` - Troubleshooting guides and technical references
|
||||||
|
|||||||
6
scripts/tdarr-manager
Executable file
6
scripts/tdarr-manager
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Tdarr Manager - Quick access to Tdarr scheduler controls
|
||||||
|
# This is a convenience script that forwards to the main manager
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||||
|
exec "${SCRIPT_DIR}/tdarr/tdarr-schedule-manager.sh" "$@"
|
||||||
169
scripts/tdarr/README.md
Normal file
169
scripts/tdarr/README.md
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
# Tdarr Gaming-Aware Scheduler
|
||||||
|
|
||||||
|
Intelligent Tdarr node management with automatic gaming detection and flexible time-based scheduling.
|
||||||
|
|
||||||
|
## 🎮 Overview
|
||||||
|
|
||||||
|
This system automatically manages your Tdarr transcoding node to avoid conflicts with gaming and other GPU-intensive activities. It detects gaming processes, monitors GPU usage, and respects customizable time windows.
|
||||||
|
|
||||||
|
## 📁 Files
|
||||||
|
|
||||||
|
| File | Purpose |
|
||||||
|
|------|---------|
|
||||||
|
| `start-tdarr-gpu-podman-clean.sh` | Start Tdarr container with GPU support |
|
||||||
|
| `stop-tdarr-gpu-podman.sh` | Stop Tdarr container |
|
||||||
|
| `tdarr-cron-check-configurable.sh` | Main scheduler (runs every minute via cron) |
|
||||||
|
| `tdarr-schedule-manager.sh` | Management interface and configuration tool |
|
||||||
|
| `tdarr-schedule.conf` | Configuration file with schedule and settings |
|
||||||
|
|
||||||
|
## 🧹 Automated Maintenance
|
||||||
|
|
||||||
|
### Temporary Directory Cleanup
|
||||||
|
A cron job automatically cleans up abandoned Tdarr transcoding directories:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Runs every 6 hours (12 AM, 6 AM, 12 PM, 6 PM)
|
||||||
|
0 */6 * * * find /tmp -name "tdarr-workDir2-*" -type d -mmin +360 -exec rm -rf {} \; 2>/dev/null || true
|
||||||
|
```
|
||||||
|
|
||||||
|
**What it does:**
|
||||||
|
- Removes Tdarr temp directories older than 6 hours
|
||||||
|
- Protects active transcoding jobs (< 6 hours old)
|
||||||
|
- Prevents `/tmp` from filling up with abandoned work files
|
||||||
|
- Safe to run - only targets Tdarr-specific directories
|
||||||
|
|
||||||
|
**When cleanup happens:**
|
||||||
|
- Failed transcoding jobs leave `tdarr-workDir2-*` directories
|
||||||
|
- Gaming interruptions can abandon partial work
|
||||||
|
- Cleanup preserves resume capability for active jobs
|
||||||
|
|
||||||
|
## 🚀 Quick Start
|
||||||
|
|
||||||
|
1. **Install the scheduler:**
|
||||||
|
```bash
|
||||||
|
./tdarr-schedule-manager.sh install
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Check current status:**
|
||||||
|
```bash
|
||||||
|
./tdarr-schedule-manager.sh status
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Test your current schedule:**
|
||||||
|
```bash
|
||||||
|
./tdarr-schedule-manager.sh test
|
||||||
|
```
|
||||||
|
|
||||||
|
## ⚙️ Configuration
|
||||||
|
|
||||||
|
### Apply Quick Presets
|
||||||
|
```bash
|
||||||
|
./tdarr-schedule-manager.sh preset night-only # 10PM-7AM only
|
||||||
|
./tdarr-schedule-manager.sh preset work-safe # Nights + work hours
|
||||||
|
./tdarr-schedule-manager.sh preset weekend-heavy # Maximum transcoding time
|
||||||
|
./tdarr-schedule-manager.sh preset gaming-only # No time limits, gaming detection only
|
||||||
|
```
|
||||||
|
|
||||||
|
### Custom Schedule Format
|
||||||
|
Edit `tdarr-schedule.conf` or use the manager:
|
||||||
|
```bash
|
||||||
|
./tdarr-schedule-manager.sh edit
|
||||||
|
```
|
||||||
|
|
||||||
|
**Time Block Format:** `"HOUR_START-HOUR_END:DAYS"`
|
||||||
|
- `"22-07:daily"` - 10PM to 7AM every day (overnight)
|
||||||
|
- `"09-17:1-5"` - 9AM to 5PM Monday-Friday
|
||||||
|
- `"14-16:6,7"` - 2PM to 4PM Saturday and Sunday
|
||||||
|
- `"08-20:6-7"` - 8AM to 8PM weekends only
|
||||||
|
|
||||||
|
## 🎮 Gaming Detection
|
||||||
|
|
||||||
|
Automatically detects these processes:
|
||||||
|
- Steam, Lutris, Heroic Games Launcher
|
||||||
|
- Wine, Bottles (Windows compatibility layers)
|
||||||
|
- GameMode, MangoHUD (gaming utilities)
|
||||||
|
- **GPU usage >15%** (configurable threshold)
|
||||||
|
|
||||||
|
## 📊 Monitoring
|
||||||
|
|
||||||
|
### View Status
|
||||||
|
```bash
|
||||||
|
./tdarr-schedule-manager.sh status
|
||||||
|
```
|
||||||
|
|
||||||
|
### Follow Real-time Logs
|
||||||
|
```bash
|
||||||
|
./tdarr-schedule-manager.sh logs
|
||||||
|
tail -f /tmp/tdarr-scheduler.log
|
||||||
|
```
|
||||||
|
|
||||||
|
### Check if Current Time is Allowed
|
||||||
|
```bash
|
||||||
|
./tdarr-schedule-manager.sh test
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🔧 Manual Override
|
||||||
|
|
||||||
|
### Start/Stop Manually
|
||||||
|
```bash
|
||||||
|
./start-tdarr-gpu-podman-clean.sh # Manual start
|
||||||
|
./stop-tdarr-gpu-podman.sh # Manual stop
|
||||||
|
```
|
||||||
|
|
||||||
|
### Remove Scheduler
|
||||||
|
```bash
|
||||||
|
crontab -e # Delete the tdarr line
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🎯 How It Works
|
||||||
|
|
||||||
|
1. **Cron runs every minute** → checks gaming processes & GPU usage
|
||||||
|
2. **Gaming detected** → immediately stops Tdarr
|
||||||
|
3. **No gaming + allowed time** → starts Tdarr
|
||||||
|
4. **Outside allowed hours** → stops Tdarr
|
||||||
|
5. **Logs all activity** → `/tmp/tdarr-scheduler.log`
|
||||||
|
|
||||||
|
## 🏗️ Architecture
|
||||||
|
|
||||||
|
```
|
||||||
|
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
|
||||||
|
│ cron (1min) │───▶│ configurable.sh │───▶│ start/stop.sh │
|
||||||
|
└─────────────────┘ └──────────────────┘ └─────────────────┘
|
||||||
|
│
|
||||||
|
┌────────▼────────┐
|
||||||
|
│ schedule.conf │
|
||||||
|
│ - Time blocks │
|
||||||
|
│ - Gaming procs │
|
||||||
|
│ - GPU threshold │
|
||||||
|
└─────────────────┘
|
||||||
|
```
|
||||||
|
|
||||||
|
## 🚨 Troubleshooting
|
||||||
|
|
||||||
|
### Check Cron Installation
|
||||||
|
```bash
|
||||||
|
crontab -l | grep tdarr
|
||||||
|
# Should show both:
|
||||||
|
# * * * * * .../tdarr-cron-check-configurable.sh (scheduler)
|
||||||
|
# 0 */6 * * * find /tmp -name "tdarr-workDir2-*"... (cleanup)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Verify Podman Access
|
||||||
|
```bash
|
||||||
|
podman ps # Should work without errors
|
||||||
|
```
|
||||||
|
|
||||||
|
### Test Gaming Detection
|
||||||
|
```bash
|
||||||
|
# Start Steam/game, then check:
|
||||||
|
tail -1 /tmp/tdarr-scheduler.log
|
||||||
|
```
|
||||||
|
|
||||||
|
### Reset to Defaults
|
||||||
|
```bash
|
||||||
|
./tdarr-schedule-manager.sh preset work-safe
|
||||||
|
./tdarr-schedule-manager.sh install
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
*Generated by Claude Code - Gaming-aware home lab automation*
|
||||||
14
scripts/tdarr/stop-tdarr-gpu-podman.sh
Executable file
14
scripts/tdarr/stop-tdarr-gpu-podman.sh
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Stop Tdarr Node Script
|
||||||
|
set -e
|
||||||
|
|
||||||
|
CONTAINER_NAME="tdarr-node-gpu-unmapped"
|
||||||
|
|
||||||
|
echo "🛑 Stopping Tdarr Node: ${CONTAINER_NAME}"
|
||||||
|
|
||||||
|
if podman ps --format "{{.Names}}" | grep -q "^${CONTAINER_NAME}$"; then
|
||||||
|
podman stop "${CONTAINER_NAME}" 2>/dev/null || true
|
||||||
|
echo "✅ Tdarr Node stopped successfully"
|
||||||
|
else
|
||||||
|
echo "ℹ️ Tdarr Node was not running"
|
||||||
|
fi
|
||||||
142
scripts/tdarr/tdarr-cron-check-configurable.sh
Executable file
142
scripts/tdarr/tdarr-cron-check-configurable.sh
Executable file
@ -0,0 +1,142 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Configurable Tdarr Gaming Scheduler (Cron Version)
|
||||||
|
# Uses tdarr-schedule.conf for flexible time-based scheduling
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||||
|
CONFIG_FILE="${SCRIPT_DIR}/tdarr-schedule.conf"
|
||||||
|
|
||||||
|
# Load configuration
|
||||||
|
if [[ -f "$CONFIG_FILE" ]]; then
|
||||||
|
source "$CONFIG_FILE"
|
||||||
|
else
|
||||||
|
echo "ERROR: Configuration file not found: $CONFIG_FILE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set defaults if not configured
|
||||||
|
GAMING_PROCESSES=${GAMING_PROCESSES:-("steam" "lutris" "heroic" "gamemode")}
|
||||||
|
GPU_THRESHOLD=${GPU_THRESHOLD:-15}
|
||||||
|
CONTAINER_NAME=${CONTAINER_NAME:-"tdarr-node-gpu-unmapped"}
|
||||||
|
LOG_FILE=${LOG_FILE:-"/tmp/tdarr-scheduler.log"}
|
||||||
|
CHECK_GAMING_ONLY=${CHECK_GAMING_ONLY:-false}
|
||||||
|
QUIET_MODE=${QUIET_MODE:-false}
|
||||||
|
|
||||||
|
log() {
|
||||||
|
if [[ "$QUIET_MODE" != "true" ]]; then
|
||||||
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >> "$LOG_FILE"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
is_gaming() {
|
||||||
|
# Check for gaming processes
|
||||||
|
for process in "${GAMING_PROCESSES[@]}"; do
|
||||||
|
if pgrep -f "$process" >/dev/null 2>&1; then
|
||||||
|
return 0 # Gaming detected
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Check GPU usage as backup indicator, but exclude Tdarr's own usage
|
||||||
|
if command -v nvidia-smi >/dev/null 2>&1; then
|
||||||
|
local gpu_usage=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits 2>/dev/null || echo "0")
|
||||||
|
if [[ $gpu_usage -gt $GPU_THRESHOLD ]]; then
|
||||||
|
# Check if Tdarr is running and likely causing the GPU usage
|
||||||
|
if is_tdarr_running && podman exec "$CONTAINER_NAME" pgrep -f "ffmpeg" >/dev/null 2>&1; then
|
||||||
|
log "📹 High GPU usage (${gpu_usage}%) but Tdarr transcoding active - ignoring"
|
||||||
|
return 1 # Not gaming, just Tdarr working
|
||||||
|
else
|
||||||
|
log "🎮 High GPU usage detected: ${gpu_usage}%"
|
||||||
|
return 0 # Gaming likely happening
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 1 # No gaming
|
||||||
|
}
|
||||||
|
|
||||||
|
is_tdarr_running() {
|
||||||
|
podman ps --format "{{.Names}}" | grep -q "^${CONTAINER_NAME}$"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_time_allowed() {
|
||||||
|
# If gaming-only mode, always allow (time restrictions ignored)
|
||||||
|
if [[ "$CHECK_GAMING_ONLY" == "true" ]]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
local current_hour=$(date +%H | sed 's/^0//') # Remove leading zero
|
||||||
|
local current_day=$(date +%u) # 1=Monday, 7=Sunday
|
||||||
|
|
||||||
|
# Check each time block in ALLOWED_TIMES
|
||||||
|
for time_block in "${ALLOWED_TIMES[@]}"; do
|
||||||
|
# Parse format: HOUR_START-HOUR_END:DAYS
|
||||||
|
local hours_part=$(echo "$time_block" | cut -d':' -f1)
|
||||||
|
local days_part=$(echo "$time_block" | cut -d':' -f2)
|
||||||
|
|
||||||
|
local start_hour=$(echo "$hours_part" | cut -d'-' -f1 | sed 's/^0//')
|
||||||
|
local end_hour=$(echo "$hours_part" | cut -d'-' -f2 | sed 's/^0//')
|
||||||
|
|
||||||
|
# Check if current day matches
|
||||||
|
local day_match=false
|
||||||
|
if [[ "$days_part" == "daily" ]]; then
|
||||||
|
day_match=true
|
||||||
|
else
|
||||||
|
# Check specific days (e.g., "1-5" or "3,5")
|
||||||
|
if [[ "$days_part" =~ ^[0-9]-[0-9]$ ]]; then
|
||||||
|
# Range format (e.g., "1-5")
|
||||||
|
local start_day=$(echo "$days_part" | cut -d'-' -f1)
|
||||||
|
local end_day=$(echo "$days_part" | cut -d'-' -f2)
|
||||||
|
if [[ $current_day -ge $start_day && $current_day -le $end_day ]]; then
|
||||||
|
day_match=true
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Comma-separated format (e.g., "1,3,5")
|
||||||
|
if [[ ",$days_part," =~ ,$current_day, ]]; then
|
||||||
|
day_match=true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if current time matches and day matches
|
||||||
|
if [[ "$day_match" == "true" ]]; then
|
||||||
|
# Handle overnight periods (e.g., 22-07)
|
||||||
|
if [[ $start_hour -gt $end_hour ]]; then
|
||||||
|
# Overnight: 22-07 means 22:00-23:59 OR 00:00-07:59
|
||||||
|
if [[ $current_hour -ge $start_hour || $current_hour -le $end_hour ]]; then
|
||||||
|
return 0 # Time allowed
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Same day: 09-17 means 09:00-17:59
|
||||||
|
if [[ $current_hour -ge $start_hour && $current_hour -le $end_hour ]]; then
|
||||||
|
return 0 # Time allowed
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
return 1 # Time not allowed
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main logic
|
||||||
|
if is_gaming; then
|
||||||
|
# Gaming detected - stop Tdarr if running
|
||||||
|
if is_tdarr_running; then
|
||||||
|
log "🎮 Gaming detected - Stopping Tdarr Node"
|
||||||
|
"${SCRIPT_DIR}/stop-tdarr-gpu-podman.sh" >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# No gaming - check if we should start Tdarr
|
||||||
|
if is_time_allowed; then
|
||||||
|
if ! is_tdarr_running; then
|
||||||
|
local current_time=$(date '+%H:%M')
|
||||||
|
log "🎬 Starting Tdarr Node at ${current_time} (allowed time, no gaming)"
|
||||||
|
"${SCRIPT_DIR}/start-tdarr-gpu-podman-clean.sh" >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Not allowed time - stop if running
|
||||||
|
if is_tdarr_running; then
|
||||||
|
local current_time=$(date '+%H:%M')
|
||||||
|
log "⏰ Stopping Tdarr Node at ${current_time} (outside allowed hours)"
|
||||||
|
"${SCRIPT_DIR}/stop-tdarr-gpu-podman.sh" >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
265
scripts/tdarr/tdarr-schedule-manager.sh
Executable file
265
scripts/tdarr/tdarr-schedule-manager.sh
Executable file
@ -0,0 +1,265 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Tdarr Schedule Manager - Easy configuration and testing tool
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||||
|
CONFIG_FILE="${SCRIPT_DIR}/tdarr-schedule.conf"
|
||||||
|
CRON_SCRIPT="${SCRIPT_DIR}/tdarr-cron-check-configurable.sh"
|
||||||
|
|
||||||
|
show_help() {
|
||||||
|
cat << EOF
|
||||||
|
Tdarr Schedule Manager
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
$0 <command> [options]
|
||||||
|
|
||||||
|
COMMANDS:
|
||||||
|
show - Show current schedule and status
|
||||||
|
edit - Open configuration file for editing
|
||||||
|
test - Test current time against schedule rules
|
||||||
|
preset <name> - Apply a preset schedule
|
||||||
|
gaming-only - Enable gaming detection only (no time limits)
|
||||||
|
enable-times - Re-enable time-based scheduling
|
||||||
|
add-time <schedule> - Add a new time block
|
||||||
|
install - Install/update the cron scheduler
|
||||||
|
logs - Show recent scheduler logs
|
||||||
|
status - Show Tdarr container status
|
||||||
|
|
||||||
|
PRESETS:
|
||||||
|
night-only - Only 10PM-7AM daily
|
||||||
|
work-safe - Weekdays 9AM-5PM + nights
|
||||||
|
weekend-heavy - Weekdays 9AM-5PM + nights + weekend days
|
||||||
|
minimal - Only 2AM-6AM daily (very light usage)
|
||||||
|
gaming-only - No time limits, gaming detection only
|
||||||
|
|
||||||
|
TIME FORMAT:
|
||||||
|
Examples: "22-07:daily" (10PM-7AM every day)
|
||||||
|
"09-17:1-5" (9AM-5PM Monday-Friday)
|
||||||
|
"14-16:6,7" (2PM-4PM Saturday,Sunday)
|
||||||
|
|
||||||
|
EXAMPLES:
|
||||||
|
$0 show # Show current configuration
|
||||||
|
$0 preset night-only # Set to nights only
|
||||||
|
$0 add-time "08-10:6-7" # Add weekend mornings
|
||||||
|
$0 test # Test if current time is allowed
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
show_current_config() {
|
||||||
|
echo "📋 Current Tdarr Schedule Configuration"
|
||||||
|
echo "======================================"
|
||||||
|
|
||||||
|
if [[ -f "$CONFIG_FILE" ]]; then
|
||||||
|
echo "🕐 Allowed Time Blocks:"
|
||||||
|
grep -E '^[[:space:]]*"[0-9]' "$CONFIG_FILE" | sed 's/^[[:space:]]*/ /'
|
||||||
|
echo
|
||||||
|
|
||||||
|
echo "🎮 Gaming Processes:"
|
||||||
|
grep -A1 'GAMING_PROCESSES=' "$CONFIG_FILE" | tail -1 | sed 's/^[[:space:]]*/ /'
|
||||||
|
|
||||||
|
echo "⚙️ Settings:"
|
||||||
|
echo " GPU Threshold: $(grep 'GPU_THRESHOLD=' "$CONFIG_FILE" | cut -d'=' -f2)"
|
||||||
|
echo " Gaming Only Mode: $(grep 'CHECK_GAMING_ONLY=' "$CONFIG_FILE" | cut -d'=' -f2)"
|
||||||
|
echo " Quiet Mode: $(grep 'QUIET_MODE=' "$CONFIG_FILE" | cut -d'=' -f2)"
|
||||||
|
else
|
||||||
|
echo "❌ Configuration file not found: $CONFIG_FILE"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
test_current_time() {
|
||||||
|
echo "🧪 Testing Current Time Against Schedule"
|
||||||
|
echo "======================================="
|
||||||
|
echo "Current Time: $(date '+%A, %B %d at %H:%M')"
|
||||||
|
echo "Current Day: $(date +%u) (1=Monday, 7=Sunday)"
|
||||||
|
echo
|
||||||
|
|
||||||
|
if [[ -x "$CRON_SCRIPT" ]]; then
|
||||||
|
# Create a test version that shows the result
|
||||||
|
local test_result
|
||||||
|
export QUIET_MODE=true
|
||||||
|
if source "$CONFIG_FILE" && [[ "$CHECK_GAMING_ONLY" == "true" ]]; then
|
||||||
|
echo "✅ ALLOWED - Gaming-only mode is enabled"
|
||||||
|
else
|
||||||
|
# Test the is_time_allowed function
|
||||||
|
bash -c "
|
||||||
|
source '$CONFIG_FILE'
|
||||||
|
$(declare -f is_time_allowed)
|
||||||
|
|
||||||
|
current_hour=\$(date +%H | sed 's/^0//')
|
||||||
|
current_day=\$(date +%u)
|
||||||
|
|
||||||
|
if is_time_allowed; then
|
||||||
|
echo '✅ ALLOWED - Current time matches configured schedule'
|
||||||
|
else
|
||||||
|
echo '❌ NOT ALLOWED - Current time outside configured schedule'
|
||||||
|
fi
|
||||||
|
" 2>/dev/null || echo "⚠️ Error testing schedule"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "❌ Scheduler script not found or not executable"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
apply_preset() {
|
||||||
|
local preset="$1"
|
||||||
|
|
||||||
|
case "$preset" in
|
||||||
|
"night-only")
|
||||||
|
cat > "$CONFIG_FILE" << 'EOF'
|
||||||
|
# Night-only preset: Tdarr runs 10PM-7AM daily
|
||||||
|
ALLOWED_TIMES=(
|
||||||
|
"22-07:daily" # 10PM to 7AM every day
|
||||||
|
)
|
||||||
|
GAMING_PROCESSES=("steam" "lutris" "heroic" "gamemode" "mangohud" "wine" "bottles")
|
||||||
|
GPU_THRESHOLD=15
|
||||||
|
CHECK_GAMING_ONLY=false
|
||||||
|
CONTAINER_NAME="tdarr-node-gpu-unmapped"
|
||||||
|
LOG_FILE="/tmp/tdarr-scheduler.log"
|
||||||
|
STARTUP_DELAY=5
|
||||||
|
QUIET_MODE=false
|
||||||
|
EOF
|
||||||
|
echo "✅ Applied preset: Night-only (10PM-7AM daily)"
|
||||||
|
;;
|
||||||
|
"work-safe")
|
||||||
|
cat > "$CONFIG_FILE" << 'EOF'
|
||||||
|
# Work-safe preset: Nights + work hours on weekdays
|
||||||
|
ALLOWED_TIMES=(
|
||||||
|
"22-07:daily" # 10PM to 7AM every day
|
||||||
|
"09-17:1-5" # 9AM to 5PM Monday-Friday
|
||||||
|
)
|
||||||
|
GAMING_PROCESSES=("steam" "lutris" "heroic" "gamemode" "mangohud" "wine" "bottles")
|
||||||
|
GPU_THRESHOLD=15
|
||||||
|
CHECK_GAMING_ONLY=false
|
||||||
|
CONTAINER_NAME="tdarr-node-gpu-unmapped"
|
||||||
|
LOG_FILE="/tmp/tdarr-scheduler.log"
|
||||||
|
STARTUP_DELAY=5
|
||||||
|
QUIET_MODE=false
|
||||||
|
EOF
|
||||||
|
echo "✅ Applied preset: Work-safe (nights + weekday work hours)"
|
||||||
|
;;
|
||||||
|
"weekend-heavy")
|
||||||
|
cat > "$CONFIG_FILE" << 'EOF'
|
||||||
|
# Weekend-heavy preset: Maximum transcoding time
|
||||||
|
ALLOWED_TIMES=(
|
||||||
|
"22-07:daily" # 10PM to 7AM every day
|
||||||
|
"09-17:1-5" # 9AM to 5PM Monday-Friday
|
||||||
|
"08-20:6-7" # 8AM to 8PM weekends
|
||||||
|
)
|
||||||
|
GAMING_PROCESSES=("steam" "lutris" "heroic" "gamemode" "mangohud" "wine" "bottles")
|
||||||
|
GPU_THRESHOLD=15
|
||||||
|
CHECK_GAMING_ONLY=false
|
||||||
|
CONTAINER_NAME="tdarr-node-gpu-unmapped"
|
||||||
|
LOG_FILE="/tmp/tdarr-scheduler.log"
|
||||||
|
STARTUP_DELAY=5
|
||||||
|
QUIET_MODE=false
|
||||||
|
EOF
|
||||||
|
echo "✅ Applied preset: Weekend-heavy (nights + work hours + most of weekend)"
|
||||||
|
;;
|
||||||
|
"minimal")
|
||||||
|
cat > "$CONFIG_FILE" << 'EOF'
|
||||||
|
# Minimal preset: Very light usage, deep night hours only
|
||||||
|
ALLOWED_TIMES=(
|
||||||
|
"02-06:daily" # 2AM to 6AM every day
|
||||||
|
)
|
||||||
|
GAMING_PROCESSES=("steam" "lutris" "heroic" "gamemode" "mangohud" "wine" "bottles")
|
||||||
|
GPU_THRESHOLD=15
|
||||||
|
CHECK_GAMING_ONLY=false
|
||||||
|
CONTAINER_NAME="tdarr-node-gpu-unmapped"
|
||||||
|
LOG_FILE="/tmp/tdarr-scheduler.log"
|
||||||
|
STARTUP_DELAY=5
|
||||||
|
QUIET_MODE=false
|
||||||
|
EOF
|
||||||
|
echo "✅ Applied preset: Minimal (2AM-6AM daily only)"
|
||||||
|
;;
|
||||||
|
"gaming-only")
|
||||||
|
sed -i 's/CHECK_GAMING_ONLY=false/CHECK_GAMING_ONLY=true/' "$CONFIG_FILE"
|
||||||
|
echo "✅ Applied preset: Gaming-only mode (no time restrictions)"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "❌ Unknown preset: $preset"
|
||||||
|
echo "Available presets: night-only, work-safe, weekend-heavy, minimal, gaming-only"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
show_status() {
|
||||||
|
echo "📊 Tdarr System Status"
|
||||||
|
echo "====================="
|
||||||
|
|
||||||
|
# Container status
|
||||||
|
if podman ps --format "{{.Names}}\t{{.Status}}" | grep -q "tdarr-node-gpu"; then
|
||||||
|
echo "🟢 Tdarr Container: RUNNING"
|
||||||
|
podman ps --format "{{.Names}}\t{{.Status}}\t{{.CreatedAt}}" | grep tdarr
|
||||||
|
else
|
||||||
|
echo "🔴 Tdarr Container: STOPPED"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Cron status
|
||||||
|
if crontab -l 2>/dev/null | grep -q "tdarr-cron-check"; then
|
||||||
|
echo "🟢 Cron Scheduler: ACTIVE"
|
||||||
|
echo " $(crontab -l | grep tdarr-cron-check)"
|
||||||
|
else
|
||||||
|
echo "🔴 Cron Scheduler: NOT INSTALLED"
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
|
||||||
|
# Recent activity
|
||||||
|
if [[ -f "/tmp/tdarr-scheduler.log" ]]; then
|
||||||
|
echo "📋 Last 3 scheduler events:"
|
||||||
|
tail -3 /tmp/tdarr-scheduler.log | sed 's/^/ /'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install_scheduler() {
|
||||||
|
echo "🔧 Installing/Updating Configurable Tdarr Scheduler"
|
||||||
|
|
||||||
|
# Update crontab to use new script
|
||||||
|
(crontab -l 2>/dev/null | grep -v "tdarr-cron-check"; echo "* * * * * $CRON_SCRIPT") | crontab -
|
||||||
|
|
||||||
|
echo "✅ Scheduler updated in crontab"
|
||||||
|
echo "🔍 Current cron entry:"
|
||||||
|
crontab -l | grep tdarr-cron-check
|
||||||
|
}
|
||||||
|
|
||||||
|
case "${1:-help}" in
|
||||||
|
"show"|"config")
|
||||||
|
show_current_config
|
||||||
|
;;
|
||||||
|
"edit")
|
||||||
|
${EDITOR:-nano} "$CONFIG_FILE"
|
||||||
|
;;
|
||||||
|
"test")
|
||||||
|
test_current_time
|
||||||
|
;;
|
||||||
|
"preset")
|
||||||
|
if [[ -n "$2" ]]; then
|
||||||
|
apply_preset "$2"
|
||||||
|
else
|
||||||
|
echo "❌ Please specify a preset name"
|
||||||
|
echo "Available: night-only, work-safe, weekend-heavy, minimal, gaming-only"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
"gaming-only")
|
||||||
|
sed -i 's/CHECK_GAMING_ONLY=false/CHECK_GAMING_ONLY=true/' "$CONFIG_FILE"
|
||||||
|
echo "✅ Gaming-only mode enabled (no time restrictions)"
|
||||||
|
;;
|
||||||
|
"enable-times")
|
||||||
|
sed -i 's/CHECK_GAMING_ONLY=true/CHECK_GAMING_ONLY=false/' "$CONFIG_FILE"
|
||||||
|
echo "✅ Time-based scheduling re-enabled"
|
||||||
|
;;
|
||||||
|
"install")
|
||||||
|
install_scheduler
|
||||||
|
;;
|
||||||
|
"status")
|
||||||
|
show_status
|
||||||
|
;;
|
||||||
|
"logs")
|
||||||
|
echo "📋 Recent Tdarr Scheduler Logs:"
|
||||||
|
tail -20 /tmp/tdarr-scheduler.log 2>/dev/null || echo "No logs found"
|
||||||
|
;;
|
||||||
|
"help"|*)
|
||||||
|
show_help
|
||||||
|
;;
|
||||||
|
esac
|
||||||
13
scripts/tdarr/tdarr-schedule.conf
Normal file
13
scripts/tdarr/tdarr-schedule.conf
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Weekend-heavy preset: Maximum transcoding time
|
||||||
|
ALLOWED_TIMES=(
|
||||||
|
"22-07:daily" # 10PM to 7AM every day
|
||||||
|
"09-17:1-5" # 9AM to 5PM Monday-Friday
|
||||||
|
"08-20:6-7" # 8AM to 8PM weekends
|
||||||
|
)
|
||||||
|
GAMING_PROCESSES=("steam" "lutris" "heroic" "gamemode" "mangohud" "wine" "bottles")
|
||||||
|
GPU_THRESHOLD=95
|
||||||
|
CHECK_GAMING_ONLY=true
|
||||||
|
CONTAINER_NAME="tdarr-node-gpu-unmapped"
|
||||||
|
LOG_FILE="/tmp/tdarr-scheduler.log"
|
||||||
|
STARTUP_DELAY=5
|
||||||
|
QUIET_MODE=false
|
||||||
Loading…
Reference in New Issue
Block a user