Plex server unable to restart after power interruption

Server Version#: 1.25.0.5282

I have a QNAP NAS and after every power interruption, all services restart smoothly, except Plex.

Plex shows an error in the log that it is either already running or wasn’t stopped properly. I’m sure this should not happen, it is possible to read the PID file, check if the process with this ID exists, and if it is Plex or not. So that it is possible to automatically recover after a crash, without having me login to NAS and do this manually. Behavior like this turns my NAS into a PC that I have to maintain constantly.

The note seems perfectly correct, restart Plex. I would be way more worried about power interruptions on your NAS / RAID. In all sincerity you would be better served with a UPS to protect your NAS, those interruptions WILL eventually corrupt your data and raid array!

Your NAS is not designed to have power interruptions, the action Plex is requiring is perfectly normal for improper shutdowns, your lucky a lot worse has not happened to your NAS.

Hi @skwor01, I understand those power interruptions aren’t good but I’m also pretty sure Plex should not worry about my data and RAID, and I believe it fails to restart because of another reason, not because it wants to tell me I need a UPS :wink: It’s not a NAS-only software, can be running anywhere and power outages are possible.

The NAS itself was able to recover and restart all services, except Plex. And the value of that I have to log in, click stop/start is rather negative. When I’m not at home and this happens my family won’t be able to do that. The server should be able to take care of itself whenever possible and should fail to restart when this really needs help. Otherwise, this looks just like a bug that I have to fix myself every time because developers are too lazy to take care of it.

Another reason might be in my NAS, though. If it doesn’t clean up some values in its registry after the crash and Plex simply doesn’t know how to deal with that. But I’m skeptical because all the other services restarted just fine and didn’t require my intervention.

That is indeed strange, since there’s already a check for that in the startup script

# Is PMS already running?
    if [ -f "$PID_FILE" ]; then

      # Pid file was present, but sadly QNAP does a very brutal kill when shutting down.
      # Verify we only have a stray PID file (no active processes).
      ProcessCount=$(ps -ef | grep plex | wc -l)
      if [ $ProcessCount -gt 1 ]; then
        logMsg="Plex Media Server is currently running or hasn't been shutdown properly. Please stop it from QNAP AppCenter and start it again."
        echo $logMsg
        /sbin/log_tool -t 2 -a "$logMsg"
        exit 0
      fi
    fi

Next time it happens, could you from a console type the following:

ps -ef | grep plex 

And then show us the result of above?

I would very much be interested in seeing Plex’s logs

Using the PlexData share, manually create a ZIP of the Logs.

then download and attach please.

Sure, I’ll check both the existing process and logs. Last time I did log in to NAS and checked processes in htop but didn’t see Plex there. Though ps would be more reliable as I may simply didn’t notice it in htop.

So I just manually unplugged my NAS from the socket and restarted. The issue was reproduced successfully. But I see neither the process nor the PID file, at least not in the /var/run/ directory.

So What I figured out is that Plex stores its PID and logs in the installation directory:

[heaven@TVS ~]$ ls -l /share/ZFS530_DATA/.qpkg/PlexMediaServer/Library/Plex\ Media\ Server/
total 142
drwxr-xr-x 6 admin administrators   16 2021-12-04 08:49 Cache/
drwxr-xr-x 4 admin administrators    6 2021-12-01 12:09 Codecs/
drwxr-xr-x 5 admin administrators    5 2021-12-01 12:09 Crash Reports/
drwxrwxrwx 2 admin administrators    2 2021-10-08 02:02 Diagnostics/
drwxr-xr-x 3 admin administrators   60 2021-12-04 04:55 Logs/
drwxr-xr-x 3 admin administrators    3 2021-10-03 23:20 Media/
drwxr-xr-x 4 admin administrators    4 2021-10-04 21:42 Metadata/
-rw-r--r-- 1 admin administrators    5 2021-12-03 13:10 plexmediaserver.pid
drwxr-xr-x 2 admin administrators    2 2021-10-03 18:59 Plug-ins/
drwxr-xr-x 7 admin administrators    7 2021-10-03 18:59 Plug-in Support/
-rw-rw-rw- 1 admin administrators 1682 2021-12-03 13:11 Preferences.xml

The file contains a PID of a non-existent process. Nothing useful in the logs, though. Since nobody used Plex the logs were not updated since yesterday.

I also found it in the code snippet that checks for the existing process in /etc/init.d/plex.sh but unfortunately, something goes wrong here.

What did above show?

It showed just one line that contained the grep command itself. The condition below checks the number of lines to be gt than 1, taking this line into account.

When I clicked stop in QuTS the pidfile was removed and next attempt to start Plex was successful.

If I may recommend using

ps -ef | grep -i plex 

I recommend this because the name is PlexMediaServer. “plex” won’t match in all cases.

This is not fixed in version 1.25.3.5409. Is there any place I can fill a bug report?

You already have right here :wink:

What does

ps -ef | grep -i plex

output?

It shows one line with the grep command itself:

[heaven@TVS ~]$ ps -ef | grep plex
24293 heaven     1024 S   grep plex
[heaven@TVS ~]$

I’d suggest using this command instead ps -ef | grep -i "[p]lex" and check whether the output is > 0

if [ $ProcessCount -gt 0 ]; then

I’m not a big shell expert but just curious if there’s an issue with the string/integer conversion, like if $ProcessCount is a String and you need to do something like this

$(($ProcessCount + 0))

What happens if you in the console type:

$(getcfg -f /etc/config/qpkg.conf PlexMediaServer Install_path)/plex.sh start

I had the same problem with my Qnap 230. I solved it by making script for plex autorun.
https://wiki.qnap.com/wiki/Running_Your_Own_Application_at_Startup

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