Plex not automatically launching on after rebooting QNAP

I wouldn’t waste the time on it. Uninstall PMS and let it be removed (part of normal uninstall)

My actions would be:

  1. Get the UPS ( I use these for small systems like yours
  1. Get it connected up (USB cable) , Configure QTS to handle shutdown, restart, etc)

  2. Have QTS do a full scrub of your data volumes to confirm integrity

  3. Now install PMS again.

this is not a solution - a really embarrassing workaround at best

Embarrassing?

I don’t understand.

You had a lot of bad configurations in your QNAP.

It is my experience QNAPs get messed up from abrupt power failure.

PMS is EASILY broken by abrupt power failure (the DB gets corrupted)

IMHO, the path forward to prevent the corruptions and keep PMS and QTS running correctly is to protect it with a small UPS. That’s all it takes.

( I live in an area where power interruptions are very frequent. I have a 1500VA UPS with battery because of it )

i don’t understand either.

there is no connection between this problem and either a “bad configuration” or some corruption.

the bug that PMS won’t auto-launch after a power-cut to the QNAP NAS affects everyone and happens every time, regardless of “configuration”.

since this hasn’t ben resolved after all these years and since the official position seems to be “we won’t fix it, just use a UPS”, maybe the requirement to use a UPS should be mentioned on the download page.

I would have to agree. Use a UPS is not the solution i would expect from the plex team. There must be a code fix that will make this problem go away.

Hey All,

I’ve been having the same frustrating problem on my QNAP, and the easiest way I found to “fix” the issue is by creating a script that restarts Plex after 2 minutes after starting up. I couldn’t find a solution so I thought I’d share.

I have Plex installed via QNAP App Center. I have the TS-464 (Intel based) QTS 5.2.3 so this should work for most of you.

  1. Enable ssh (Control Panel => Network & File Services => Telnet / SSH => Allow SSH)
  2. Open a terminal window
  3. ssh <username>@<ip of QNAP NAS> (Example ssh Mike@192.168.1.34 )
  4. sudo -i
  5. Quit out of the interactive mode (Q then Y)
  6. Now you’re admin@<MyNasDevice>
  7. mount $(/sbin/hal_app --get_boot_pd port_id=0)6 /tmp/config
  8. touch /tmp/config/autorun.sh
  9. chmod +x /tmp/config/autorun.sh

Okay Great now we’re setup and ready to add a delay to Plex

  1. vi /tmp/config/autorun.sh
  2. Hit the “i” key for insert
  3. Type in the following:
#!/bin/sh
sleep 120
/etc/init.d/plex.sh restart
  1. After typing the above hit the ESC key. Type in “:wq!” that will write to the file and quit, in vim.

  2. Lastly go to Control Panel => System => Hardware => Check "Run user defined processes during startup"

  3. Verify by clicking the view autorun.sh to confirm and view the changes (in Step 14).

The script above just waits 120 seconds, then restarts Plex. You can adjust the time as needed, but 120 seconds works for me. If there’s enough evidence that 60s is sufficient and it works in tests let me know and I’ll adjust.

Hope I end up solving more than a few frustrated QNAP users. I’ve never had issues with my Synology. :sweat_smile:

Thanks @dane22 for the suggestion to change the location to simplify the location to enable maximum compatibility! Teamwork makes the dreamwork!

This is great. Thanks for taking the time to do it. Im not really good with terminal commands.

Ive managed to do the ssh bit can you elaborate on the adding delay to plex? It seems the last command “:wq!” doesn’t actually quit.

I also get an error that -ld parameter cannot be found on find location command.

Whoops forgot to mention you need to hit ESC first. Then :wq!

I edited my previous post…hope it helps and thanks for letting me know!

To be clear. The autorun.sh file only really needs those two lines (sleep and the Plex restart) in it.

Instead simply use this: /etc/init.d/plex.sh restart that works on all disk layouts

1 Like

What happened between your optimism of plex.sh detecting when a crash has occurred in March 2024 to release notes for 1.40.5.8796 stating it was fixed Plex Media Server - #634 by gbooker02 to now where the solution seems to be a UPS?

@321liftoff

Beginning with

through the end of the thread, I see no reference to a UPS.

As we all know, databases do not like abrupt power-off conditions
There are times when PMS will (frequently) say “malformed” when there is no real damage only because it wasn’t a proper shutdown. ( Much like the computer OS not shutting down cleanly ). In these cases, manual intervention is required.

Do you have logs captured from the last abrupt shutdown so I can see if that’s the case ?

As for using a UPS, it’s generally good advice on ANY NAS for the sake of the filesystem. Protecting the applications, like PMS, which may be running on it is an added bonus.

I have two UPSes for my servers. My main server has an external battery.
I have these due to where I live (winter snow and violent summer storms)

i am unsure why you continue to reference “database corruption” when this thread is about the fact that Plex always does not autostart after a QNAP NAS loses power.

database damage is the ONLY way I could make it NOT start after power failure.

( I have two QNAPs and either exhibits the problem described ).

That having been said, I have another way of detecting power failures and starting .

Would it be acceptable if I implement those changes into a test plex.sh and we’ll test it here before I release it ?

2 Likes

@dinkblam

When PMS starts on a QNAP, the following happens:

  • PMS is launched, and database is opened
  • What is known as a pid file is created, that contains the process number of PMS
  • Several sub programs are launched by PMS, that is needed for other Plex related tasks

If the QNAP has a power failure, PMS can not do a proper cleanup after itself!

So during the startup script, we check if there is already a pid file present, which should not be there during normal operation

If one is found, we have the following options:

  • Check if there is a process containing the words Plex Media Serv, and if so we assume everything is okay and silently quit
  • If we could not find above process, we assume that the pid file is a left-over from an incorrect shutdown, and then search for other child processes and see if we can kill them, and then remove the offending pid file and restart PMS
  • If we can not do above, we exit with an error in the QTS console to the QNAP admin user

The only things we can not check for are the following:

  • Ports are already taken, preventing PMS from starting up
  • Database corruption, that will allow PMS to start, but end up in a non-responsive state
    • This normally happens if power is cut during a write operation to the database

Due to above we strongly recommend what should be needed for every computer/NAS running a database, is an UPS

i am not going to buy an UPS, and i have used the solution by @vtmike1 (thanks!) to finally solve it on my end.

1 Like

I bought a UPS the day I got my QNAP. I live in an area where storms wreak havoc on the power systems. Needless to say, while it worked… I didn’t have any issues.

After about two years, the batteries in it failed. I went through the worst few months of storms this year, and I can only assume my database got wrecked. I am still trying to get things back in order.

I bought a second. Sure, you’ll get by for now… but that one time… you might get wrecked too. I cannot recommend one enough.

2 Likes

Does it help your theory to know that EVERY time I have a power outage, without fail, I log into the qnap webpage and stop plex and then click start and it starts EVERY time.

If there was a database corruption issue, I would think that even stopping the app and restarting would fail.

@ChuckPa I’ll work on getting you logs. Regarding UPS, I interpreted this post as suggesting it was the actual solution to this problem.

To me, that tells me your QTS isn’t doing its job.

I will give you a custom plex.sh which will log every time it’s invoked, regardless the result.

If we find that there is indeed something wrong with plex.sh then i’ll rewrite the whole thing if I have to.

If it’s not being invoked after power fail then QNAP needs to get involved.

Fair enough?

1 Like

Chuck,

I’m wondering if the issue has to do with how the QNAP QTS Linux OS starts up the services. At first glance it seems fine (looking at /etc/rcS.d/ - it looks like the script starts up 108 out of 128 of my scripts…but wondering if there’s sufficient time to give any relying service/script to fully start.

I’d be curious to see if I could just add a delay…maybe put a “sleep 60s” in the startup script and cut power to see if that fixes the issue. Just a thought, but I’d be interested in what you think since I don’t know a lot about the this OS in particular.

@vtmike1

Those start numbers, 101 → xxx are ignored by QTS/QuTS at device startup

Per the SDK

QPKG_RC_NUM
Preferred number in start/stop sequence. Note that the value is currently ignored by the QNAP NAS after
a reboot at which point the actual number is assigned depending on the order of the applications in
/etc/config/qpkg.conf starting with 100 for the first application.

What you get is:

  1. QTS initializes
  2. Starts running /etc/config/qpkg.conf – in as-encountered order
  3. Waits predefined amount of time
  4. Starts next package
  5. Repeats steps 3-4 until done.

I have a fully instrumented plex.sh here which spits out a vast amount of logging as plex.sh runs so we can see where it fails – if it does.

From what I’ve seen so far, QTS/QuTS isn’t invoking plex.sh
( my instrumented version does log when plex.sh gets invoked in the PMS server logs so we can track it.)

I’m more than happy to share it with you or anyone to see if we can pinpoint where this failure is occurring.

I’ve gone so far now as also having PMS wait for the Nvidia GPU DRV package to start (within reason) when it can.
This covers those cases where PMS was installed before NVIDIA_GPU_DRV was installed (or reinstalled)

If you want the instrumented version, let me know and I’ll post it here.