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’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.
ssh <username>@<ip of QNAP NAS> (Example ssh Mike@192.168.1.34 )
sudo -i
Quit out of the interactive mode (Q then Y)
Now you’re admin@<MyNasDevice>
mount $(/sbin/hal_app --get_boot_pd port_id=0)6 /tmp/config
touch /tmp/config/autorun.sh
chmod +x /tmp/config/autorun.sh
Okay Great now we’re setup and ready to add a delay to Plex
vi /tmp/config/autorun.sh
Hit the “i” key for insert
Type in the following:
#!/bin/sh
sleep 120
/etc/init.d/plex.sh restart
After typing the above hit the ESC key. Type in “:wq!” that will write to the file and quit, in vim.
Lastly go to Control Panel => System => Hardware => Check "Run user defined processes during startup"
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.
Thanks @dane22 for the suggestion to change the location to simplify the location to enable maximum compatibility! Teamwork makes the dreamwork!
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?
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.
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 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.
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.
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.
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:
QTS initializes
Starts running /etc/config/qpkg.conf – in as-encountered order
Waits predefined amount of time
Starts next package
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.