Skip to content

Jellyfin Drive Wake Service

Pre-wakes NAS HDDs when users open Jellyfin, eliminating the ~25 second spin-up delay.

Script ~/scripts/jellyfin-wake-drives.py
Service jellyfin-wake.service
Status Enabled

Problem

The TerraMaster NAS spins down HDDs after 30 minutes of inactivity (/etc/tos/standby.conf). When you open Jellyfin, the UI loads instantly but playback hangs for 25+ seconds while drives spin up.

Solution

A Python service monitors Jellyfin sessions. When a new session appears (user opens app), it immediately reads small files from media folders to wake the drives before playback begins.

How It Works

Every 10s: Poll Jellyfin /Sessions API (localhost only, doesn't wake NAS)
    └─▶ New session detected?
            └─▶ Yes: Read 1KB from /mnt/nfs_media/{tvshows,movies,music}
                     ├─▶ Drives wake up in parallel (~25s)
                     └─▶ 5-minute cooldown prevents spam

Files

File Purpose
/home/monxas/scripts/jellyfin-wake-drives.py Main script
/etc/systemd/system/jellyfin-wake.service Systemd unit

Configuration

Environment variables (set in script or override via systemd):

Variable Default Description
JELLYFIN_URL http://localhost:8096 Jellyfin API endpoint
JELLYFIN_API_KEY (set in script) Jellyfin API key
POLL_INTERVAL 10 Seconds between session checks
NAS_MOUNT /mnt/nfs_media NFS mount path
WAKE_COOLDOWN 300 Minimum seconds between wake attempts

Service Management

# Status
systemctl status jellyfin-wake.service

# Logs (live)
journalctl -u jellyfin-wake.service -f

# Logs (last hour)
journalctl -u jellyfin-wake.service --since "1 hour ago"

# Restart
sudo systemctl restart jellyfin-wake.service

# Disable
sudo systemctl disable jellyfin-wake.service
sudo systemctl stop jellyfin-wake.service

Example Log Output

Jellyfin Drive Wake Service started
  Jellyfin: http://localhost:8096
  NAS Mount: /mnt/nfs_media
  Poll interval: 10s
  Wake folders: ['tvshows', 'movies', 'music']

Initial sessions: 2

[21:02:15] New session detected!
  Waking drives...
  Drives awake in 24.8s

[21:05:30] New session detected!
  Skipping wake (cooldown: 162s remaining)

NAS Details

  • Model: TerraMaster (192.168.0.237)
  • Storage: 3x 10.9TB HDD in RAID5 (~21TB usable)
  • SSD Cache: 111GB flashcache for hot files
  • Standby: 30 minutes (/etc/tos/standby.conf)
  • SSH: [email protected]

Why Not Disable Standby?

You could set standby=0 on the NAS to keep drives always spinning, but: - Increases power consumption - Increases heat and noise - Reduces drive lifespan

The wake service is a better tradeoff: drives sleep when idle, wake proactively when needed.

Troubleshooting

Service not starting?

# Check Python dependencies
python3 -c "import requests" || pip3 install requests

# Test API access
curl -s "http://localhost:8096/Sessions?api_key=YOUR_KEY"

Drives not waking?

# Test NFS mount responsiveness
timeout 30 ls /mnt/nfs_media/tvshows/

# Check if mount is stale
mount | grep nfs_media

Sessions not detected?

# Get current sessions (use your JELLYFIN_API_KEY from ~/.env)
curl -s "http://localhost:8096/Sessions?api_key=YOUR_API_KEY" | python3 -m json.tool