FreeNAS plex.pid file missing

PMS Version#: 1.20.1.3252
FreeNAS Version#: 12.0-BETA2.1

This has been an issue for a while and I’ve just sat down with some time to look at it.

I have Plex installed in a jail on my FreeNAS system using pkg.

The service start script refers to a plex.pid file which, as far as I can tell, never exists. This means I’m unable to stop the plexmediaserver service without stopping the entire jail. I’ve verified that the service script is the same as what’s in the pkg and I’m not sure where to go from here.

Any help would be appreciated.

# service plexmediaserver stop
plexmediaserver not running? (check /var/run/plex/plex.pid).
# ls /var/run/plex/plex.pid
ls: /var/run/plex/plex.pid: No such file or directory
# ps -A
  PID TT  STAT    TIME COMMAND
47474  -  IsJ  0:00.00 dhclient: epair0b [priv] (dhclient)
47533  -  ICsJ 0:00.00 dhclient: epair0b (dhclient)
47599  -  IsJ  0:00.00 /usr/sbin/syslogd -c -ss
47655  -  IsJ  0:06.30 /usr/local/share/plexmediaserver/Plex_Media_Server (Plex Media Server)
47662  -  SsJ  0:00.00 /usr/sbin/cron -J 15 -s
47691  -  INJ  0:04.70 Plex Plug-in [com.plexapp.system] /usr/local/share/plexmediaserver/Resources/Plug-ins-a78fef9a9/Framework.bundle/Contents/Resources/Versions/2/Python/bootstrap.py --s
47815  -  IJ   0:01.35 Plex Plug-in [tv.plex.agents.music] /usr/local/share/plexmediaserver/Resources/Plug-ins-a78fef9a9/Framework.bundle/Contents/Resources/Versions/2/Python/bootstrap.py -
47855  -  IJ   0:01.65 Plex Plug-in [com.plexapp.agents.themoviedb] /usr/local/share/plexmediaserver/Resources/Plug-ins-a78fef9a9/Framework.bundle/Contents/Resources/Versions/2/Python/boots
47935  -  IJ   0:01.25 Plex Plug-in [org.musicbrainz.agents.music] /usr/local/share/plexmediaserver/Resources/Plug-ins-a78fef9a9/Framework.bundle/Contents/Resources/Versions/2/Python/bootst
47959  -  IJ   0:01.66 Plex Plug-in [com.plexapp.agents.thetvdb] /usr/local/share/plexmediaserver/Resources/Plug-ins-a78fef9a9/Framework.bundle/Contents/Resources/Versions/2/Python/bootstra
47960  -  IJ   0:01.16 Plex Plug-in [tv.plex.agents.movie] /usr/local/share/plexmediaserver/Resources/Plug-ins-a78fef9a9/Framework.bundle/Contents/Resources/Versions/2/Python/bootstrap.py -
47970  -  IJ   0:01.86 Plex Plug-in [com.plexapp.agents.imdb] /usr/local/share/plexmediaserver/Resources/Plug-ins-a78fef9a9/Framework.bundle/Contents/Resources/Versions/2/Python/bootstrap.p
47930  0  SJ   0:00.02 /bin/sh
48522  0  R+J  0:00.00 ps -A

It’s possible the default for is changed in rc.conf, just It would be surprising since it’s a bar that would also be used in that message IIRC.

Does it show before you run service stop?

To preface, I’m not an expert on this stuff, I just know enough to be dangerous, and occasionally enough to keep myself out of danger.

tl;dr it’s my own dumb fault for changing the plex user’s UID.

I checked /etc/rc.conf and the only plex-related lines are…

plexmediaserver_enable="YES"
plexmediaserver_support_path="/config"

I checked /usr/local/etc/rc.d/plexmediaserver and it doesn’t look like the pidfile variable is one that can be overwritten.

I manually killed the running Plex processes so I could safely service start plexmediaserver and it started Plex without apparent issue but there’s still no pidfile and service status plexmediaserver says it’s not running.

As an extra test, I installed inotify-tools and set inotifywait to monitor /var/run/plex/ - touching and rming the pidfile prints some events, but service start plexmediaservice does not (though the service does come up correctly).

I was initially of the understanding that the /usr/sbin/daemon process was creating the pidfile as part of launching the service, but I tried debugging the service launch script and can see nowhere where the pidfile is passed to the daemon. I can see where an environment variable is set (PLEX_MEDIA_SERVER_PIDFILE=/var/run/plex/plex.pid) before running Plex with su -m which passes the existing environment to the plex user for starting the Plex service.

My conclusion was that the Plex_Media_Server binary is responsible for creating its own pidfile, and it is not doing so, or it is creating a pidfile in a different location to that specified by the PLEX_MEDIA_SERVER_PIDFILE environment variable.

Checking the Plex Media Server.log quickly shows…

Sep 07, 2020 09:34:52.643 [0x80b816000] ERROR - Error opening file '"/var/run/plex/plex.pid"' - Permission denied (13)
Sep 07, 2020 09:34:52.643 [0x80b816000] ERROR - Error writing pid file: "/var/run/plex/plex.pid"

The permissions on the /var/run/plex/ directory are 755 and the owner user:group is 972:wheel. I believe that 972 is the package’s default uid, but I’ve created/modified the plex user with uid:1000 to simplify my media sharing permissions.

I re-created the jail, and I created the plex user with uid 1000 before installing plexmediaserver (pretty sure I edited the user to change the uid last time, and then fixed permissions - but clearly missed something).

It all works now.

Sorry.

1 Like

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