Getting autosuspend to Detect Active Jellyfin Streams and Browsing

Share this:

This is a follow-up to the autosuspend post in my headless Ubuntu NUC series, which covers Samba, torrents, and SSH sessions. This one’s about Jellyfin: I didn’t want the server suspending on me mid-stream, or even while I’m just browsing the library deciding what to watch.

Why a plain port check isn’t enough

My first instinct was an ActiveConnection check against Jellyfin’s port (8096 by default), same as I did for the torrent web UI in the earlier post. Turns out Jellyfin keeps a connection open to any browser tab with the web UI loaded, whether or not anything’s actually playing. So that check would keep the server awake forever just because I left a tab open somewhere, not what I was after.

Jellyfin’s own API does this properly though. It tracks each session and tells you whether it’s actually playing something.

Checking Jellyfin’s Sessions API

Jellyfin has a /Sessions endpoint that lists every active session and what it’s doing. You’ll need an API key first, generate one from the admin dashboard under Dashboard → API Keys.

Then query it:

curl -s "http://localhost:8096/Sessions?api_key=<your-api-key>" | jq '.[] | {IsActive, NowPlayingItem}'

NowPlayingItem only shows up once something’s actually playing, so that’s my signal for real playback. IsActive is just Jellyfin’s own read on whether the session is active at all, which also catches someone browsing with nothing playing yet.

The check script

Create the script:

sudo nano /usr/local/bin/jellyfin-active-check.sh

It exits 0 if any session is either playing something or Jellyfin considers it active:

#!/bin/bash
# Exits 0 if any Jellyfin session is playing, or Jellyfin itself considers it active
curl -s "http://localhost:8096/Sessions?api_key=<your-api-key>" \
  | jq -e '.[] | select(.NowPlayingItem != null or .IsActive == true)' > /dev/null
sudo chmod +x /usr/local/bin/jellyfin-active-check.sh

This one needs jq, unlike the torrent check from the earlier post:

sudo apt install jq

Test it before wiring it into autosuspend. It won’t print anything since I’m piping output to /dev/null on purpose, so check the exit code instead:

/usr/local/bin/jellyfin-active-check.sh; echo $?

0 means it caught activity, anything else means it didn’t. If you get an error instead, check the script’s actually executable, and that you’re calling it by its full path rather than sticking a stray ./ in front of a path that’s already absolute (I’ve done this more than once).

Wiring it into autosuspend

Add it as another ExternalCommand check in /etc/autosuspend.conf, next to the Samba, torrent, and SSH checks from before:

[check.JellyfinPlayback]
class = ExternalCommand
enabled = true
command = /usr/local/bin/jellyfin-active-check.sh

Restart the service and watch the log:

sudo systemctl restart autosuspend
sudo journalctl -u autosuspend -f

With Jellyfin’s web UI open in a browser tab, you should see JellyfinPlayback matching and resetting the idle timer.

Result

The server stays awake now while I’m actually streaming, or just browsing the library with the web UI open, on top of the Samba, torrent, and SSH checks from before. It still suspends once everything, Jellyfin included, has genuinely gone idle.



If this post has been useful, support me by buying me a latte or two 🙂
Buy Me A Coffee
Share this:

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.