Plexmediaserver.pid prevents Plex startup in cases of power failure

If you google, there are a lot of people who have a lot of problems with Plex Media Server on power cuts. My one was that if the plexmediaserver.pid isn’t cleaned up by clean shutdown then it remains forever, until manual intervention.

Basically:

Aug 20 05:58:17 linux-server systemd[1]: Started Plex Media Server.
Aug 20 05:58:17 linux-server Plex Media Server[2034]: Plex Media Server is already running. Will not start...
Aug 20 05:58:17 linux-server systemd[1]: plexmediaserver.service: Main process exited, code=exited, status=1/FAILURE
Aug 20 05:58:17 linux-server systemd[1]: plexmediaserver.service: Failed with result 'exit-code'.

Behold the evil file:

root@linux-server:/var/lib/plexmediaserver/Library/Application Support/Plex Media Server# ls
 Cache   Codecs  'Crash Reports'   Logs   Media   Metadata   plexmediaserver.pid   Plug-ins  'Plug-in Support'   Preferences.xml

Whats inside the file:

root@linux-server:/var/lib/plexmediaserver/Library/Application Support/Plex Media Server# cat plexmediaserver.pid 
993

Maybe there is a process number 993 somewhere? Nope:

993root@linux-server:/var/lib/plexmediaserver/Library/Application Support/Plex Media Server# ps -aux |grep 993
root        2186  0.0  0.0   9076  2400 pts/3    S+   06:13   0:00 grep --color=auto 993

So, I have fixed this in my instance by modifying the systemd startup script to delete any stale pid files before running Plex Media Server. But if you guys want a better general user experience then I would suggest you change Plex Media Server to not just check for the presence of the pid file but also check the contents actually points to a running instance of Plex Media Server.

Not everything is shutdown nicely in the real world, and assuming that it is causes great strife for end users.

Get an online UPS with remote shutdown if you have power quality issues.

I don’t think instructing people to go purchase hardware to work around lazy programming is a good approach. There are other situations where ungraceful shutdown can occur - crashes/intermittent hardware faults. Other service software can deal with stale pid files appropriately. Again, I’ve fixed it for me, I’m trying to help you improve your software.

Wait, I’m only a user. Don’t blame plex inc based on anything I say…

Just wait till intel introduces a hardware fault injector in the next line of ■■■■■■ CPU’s. The amount of file system corruption will be too damn high! I see DoS on the horizon…

Heh, sorry, I meant you in the plural, community sense, rather than you as a specific individual. I just noticed there is a lot of results for “plex stops working after power cut” on google. And it took me the better part of an hour to work out what was going on, and I’ve been using linux for decades. So yeah, devs should fix it :slight_smile:

Folks,

I’m the Linux packaging dev for this.

Give me a bit to get into it and come up with a solution.
(dealing with systemd can get dicey)

Please tell me -

  1. Distro
  2. Version
  3. Systemd or init startup control
  4. Native app -or- VM or container (LXC or Docker)

This gives me a starting point for replicating

Thanks.

PS: Would have loved to know the UID/GID of the pid file itself as well as the UID/GID PMS runs as.

It’s just a vanilla PMS install on Ubuntu 22.04. You shouldn’t need to change anything to replicate the behavior, just install it then pull the power cord out of the back of the computer. The native app, running on physical hardware, no docker or VMs involved. The gid/uid for PMS and the pid file are the same - htpc which is the user & group that it runs as.

Thanks. I will get on this.

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