Jay's blog

I'm Restarting Plex Every 24 Hours Now

I only use Plex because the phone app and the PlayStation app make it convenient. If Jellyfin had a native app on PlayStation, I'd switch tomorrow. I already don't completely trust Plex, which is why I run it in a Podman container. If anything goes really sideways, at least the blast radius should be minimized.

Plex is also flaky. I find myself occasionally needing to SSH into my home server to restart Plex when the app can't connect to the server. No errors are ever logged from the server, and even if I went to the trouble of getting logs from the apps, I doubt I could really do anything to fix it. Plex and its apps are a black box to me. I treat them less like software and more like hermetically sealed appliances. And what do you do when a hermetically sealed appliance acts up? Power cycle it!

As much as I'd prefer perfect appliances, sometimes the power cycle approach has to be good enough. Most home routers have settings in their UI nowadays to automatically power cycle themselves on a regular schedule. Even the expensive ones! Especially the expensive ones. My phone runs GrapheneOS, which has an option to automatically power cycle your phone after a set period of inactivity. In that case, it's because your phone is subtly more secure before it's been unlocked after a power cycle. Like it or not, "Have you tried turning it off and on again?" is now the way of the world.

I'm currently in my systemd era. Sooner or later, systemd comes for us all. 🪦 The path of least resistance seems to be a service and a timer to trigger that service.

# /home/server-user/.config/systemd/user/plex-restart.service
[Unit]
Description=Restart Plex container service
Wants=plex.service
After=plex.service

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl --user is-active --quiet plex.service && /usr/bin/systemctl --user restart plex.service

The service itself only attempts to restart the Plex service if the service is already active. If I should decide to manually stop the Plex service, I don't want this job to restart it.

# /home/server-user/.config/systemd/user/plex-restart.timer
[Unit]
Description=Daily restart of Plex container service at 6 AM

[Timer]
OnCalendar=*-*-* 06:00:00
Unit=plex-restart.service

[Install]
WantedBy=timers.target

I have the timer set to go off every day at 6 AM because I can't imagine a situation where anyone in my household is using it at that time, so there shouldn't be any service interruption.

systemctl --user daemon-reload

systemctl --user start  plex-restart.timer

And with that, I hopefully won't have to restart Plex manually any time soon. Sure, I could have tried to rig up a script that detects the server's health and restart it only when necessary. But remember that Plex is a black box. Just because my server can essentially ping itself doesn't mean other devices can reach it. No, an automatic power switch flipper should be good enough.

#home server #plex #systemd