You might find these Linux scripts useful

I find that plexmediaserver could do with an update script and a watcher script. I use these on mint linux.

The update script - /root/bin/UpdatePlex.sh

#!/bin/bash

# Requires: jq, curl
# Install jq if needed: sudo apt install jq

# Get the current installed version
INSTALLED=$(dpkg -s plexmediaserver | grep '^Version' | awk '{print $2}')

# Get latest version info from Plex
LATEST=$(curl -s https://plex.tv/api/downloads/5.json | jq -r '.computer.Linux.version')

echo "Installed version: $INSTALLED"
echo "Latest version:    $LATEST"

if [ "$INSTALLED" != "$LATEST" ]; then
    echo "Update available. Downloading..."
    URL=$(curl -s https://plex.tv/api/downloads/5.json | jq -r '.computer.Linux.releases[] | select(.build=="linux-x86_64" and .distro=="debian") | .url')
    curl -L -o plex.deb "$URL"
    sudo dpkg -i plex.deb
    rm plex.deb
    echo "Update complete!"
else
    echo "Plex is already up to date."
fi

My timer that checks to see if plex is running, if not will restart it.

/usr/local/bin/check-plex.sh

#!/bin/bash

# Check if Plex is running
if ! systemctl is-active --quiet plexmediaserver; then
    echo "$(date): Plex Media Server is not running. Attempting restart..." >> /var/log/plex-monitor.log
    systemctl restart plexmediaserver
else
    echo "$(date): Plex Media Server is running fine." >> /var/log/plex-monitor.log
fi

Work on the service - /etc/systemd/system/plex-monitor.service

[Unit]
Description=Monitor and restart Plex Media Server if it's not running
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/check-plex.sh

Create the timer - /etc/systemd/system/plex-monitor.timer

[Unit]
Description=Run Plex Monitor Script Every 5 Minutes

[Timer]
OnBootSec=5min
OnUnitActiveSec=5min
Unit=plex-monitor.service

[Install]
WantedBy=timers.target

Enable and start the timer.

systemctl daemon-reexec
systemctl enable --now plex-monitor.timer

root@Linux-Plex-Server:~/bin
└─ $ ▶ $ systemctl list-timers
NEXT                            LEFT LAST                              PASSED UNIT                         ACTIVATES                     
Sat 2025-07-19 22:12:01 BST 2min 19s Sat 2025-07-19 22:07:01 BST 2min 40s ago plex-monitor.timer           plex-monitor.service
Sat 2025-07-19 22:25:55 BST    16min Sat 2025-07-19 21:39:44 BST    29min ago fwupd-refresh.timer          fwupd-refresh.service


root@Linux-Plex-Server:~/bin
└─ $ ▶ $ cat /var/log/plex-monitor.log
Sat 19 Jul 21:55:03 BST 2025: Plex Media Server is running fine.
Sat 19 Jul 21:56:58 BST 2025: Plex Media Server is running fine.
Sat 19 Jul 22:01:59 BST 2025: Plex Media Server is running fine.
Sat 19 Jul 22:07:01 BST 2025: Plex Media Server is running fine.

1 Like

You might want to add the is-enabled qualifier for those who don’t want PMS to forcibly restart every time the script runs.

You should also consider DBRepair running and optimizing the DB.
If PMS restarts in the middle of this – DB Corruption


If you enable the Repository, apt update && apt -y ugprade will do the upgrade when it’s available (Public)

Thanks, I have cloned the repo.

Cloned the repo? My repo?

Don’t clone it. It wasn’t my intent to clone DBRepair

My suggestion was to enable the Plex repository

/etc/apt/sources.list.d/plexmediaserver.list

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.