I finally had the my script hit and try to kill the plex server. I seem to be getting some false positives though. I’m currently checking-> http://127.0.0.1:32400/status/sessions and I have instances were this is timing out (taking longer than 30 seconds) and its killing the server, but other endpoints are actually responsive (playback is working). So I may try switching to just checking http://127.0.0.1:32400/status which responds instantly when /sessions does not. It is troubling why that would be taking so long though…
This endpoint was more accurate, when /status has a timeout, the server is truly hung and playback no longer works. restarting resolves things, so in that way the script is successful, but I had restarts fairly often for about an hour.
good to know, and it doesn’t require a token. the current script is working well, its just a bandaid to keep the server up, but no more baby sitting it.
this is what it looks like currently:
property plexToken : "your-token-here"
on idle
set delayTime to 15 -- default delay time
tell application "System Events"
set running_apps to every application process's name
if running_apps does not contain "Plex Media Server" then
display notification "Restarting PMS - Not Found" with title "Keep Plex Alive Script"
tell application "Plex Media Server" to activate
-- give time for Plex to startup before checking the api
delay 20
end if
-- Check Plex API for status, but only if plexToken is not empty
if plexToken is not "" then
set plexResponse to ""
try
set plexResponse to do shell script "curl --max-time 35 -s -o /dev/null -w '%{http_code}' http://127.0.0.1:32400/status?X-Plex-Token=" & plexToken & " || true"
on error errMsg
display dialog "Check Plex API curl error: " & errMsg with title "Keep Plex Alive Script"
end try
-- If getting a 503, wait a little and try again just be sure (avoid hammering kills on startup)
if plexResponse is "503" then
delay 15
try
set plexResponse to do shell script "curl --max-time 35 -s -o /dev/null -w '%{http_code}' http://127.0.0.1:32400/status?X-Plex-Token=" & plexToken & " || true"
on error errMsg
display dialog "Retry after 503 - Check Plex API curl error: " & errMsg with title "Keep Plex Alive Script"
end try
end if
if plexResponse is not "200" and plexResponse is not "" then
-- Try a normal quit first
display notification "Quiting PMS - Plex API status code: " & plexResponse with title "Keep Plex Alive Script"
tell application "Plex Media Server" to quit
-- After quitting, reset the delay time for a faster restart
set delayTime to 0
-- Wait for a bit (10 seconds)
delay 10
-- Check if Plex Media Server still running, if so, force quit
tell application "System Events"
if exists (every process whose name is "Plex Media Server") then
set plexProcesses to every process whose name is "Plex Media Server"
repeat with plexProcess in plexProcesses
display notification "Force Quit PMS - non200 API" with title "Keep Plex Alive Script"
try
do shell script "kill -9 " & (unix id of plexProcess)
on error errMsg
display dialog "Error killing process: " & errMsg with title "Keep Plex Alive Script"
end try
end repeat
end if
end tell
end if
end if
end tell
return delayTime
end idle
I’m sure you could ask chatgpt to convert it into a .bat or .sh for windows or linux
anyone know how to refresh metadata on an item via an api call? since this isn’t being addressed thinking of just writing a script that scans for newly added movies and then calls refresh metadata on it automatically.
I’m the original poster and STILL having this issue. I got the FNAF movie, it’s x265, and it played fine for me but when friends try to play it the damn thing crashes my server. When will this transcodes movie only issue be fixed? Half my movies are in x265 now and one user hammering trying to play a movie can bring down the entire server in a CPU spiral. I’ve replaced every single piece of my server, moved my transcoding off the NVidia card to the Intel chip and the only thing that works 100% of the time is to disable transcoding completely, which is the main function of PLEX…
Same here, running latest plex beta on windows 10. Only occurs to movies, never series. Tried NVIDIA and Intel GPUs for HW transcoding, no apparent difference in crashing.
Only “fix” I know of is to disable hardware transcoding completely.
This is still happening for me as well… though it doesn’t seem related to transcode at all for me as the server never even makes it to that step and gets hung on the includeRelated=1 call for the metadata… it would be interesting if changing the transcoding settings changes this behavior at all (though I would assume not) I haven’t noticed a difference for h264 vs h265 content in this problem… but it certainly can happen on both. This thread is coming up on its one year anniversary soon…
I do seem to be able to avoid the issue if I always remember to run a refresh metadata command manually on newly added movies… but its a manual step I do sometimes miss and as others have stated, the issue never happens for TV series.
My server crashed 4x yesterday thanks to the new Hunger Games movie in x256. As usual the only way to get it to play and NOT crash my server was to add it, remove it, clean bundles, and add it again.
Can someone from PLEX PLEASE FIX THIS? It’s been over a year, it only happens to x256 Movies, and a single user can bring my entire Intel 24 core, 32Gb of RAM, RTX 4070 server from trying to play 1 “broken” movie like this twice. I’ve used PLEX for years, I have a lifetime pass, until this 1 issue I was proud to be a PLEX user and now I have these roaming server crashes as a random user tries to play a new movie (it’s always new x265 movies) and brings my entire platform down.
still happening for me too; its daily and my script catches it and restarts plex for me… but the particular movie thats causing the hang/cpu load/crash remains a mystery unless someone tells me it doesn’t work as there is no log of the issue as playback can never start…
(note: api status code: 000 means there was a timeout and the plex api is not responding)
I think I’ve also started experiencing the issues in this thread, for me since around Christmas.
I’d raised my own thread but was pointed here
Are there any bandaids to the solution? I see mentioned to use the legacy movie agent? Is that literally the “Plex Movie (Legacy)” or is it “The Movie Database” agent?
I swapped to it and refreshed everything but was still having issues. I’ve just done the plex dance with all my movies and waiting for them to scan back in before i try to see if any files are failing again.
Yes using the “Plex Movie (Legacy)" agent would be the workaround. Another is to run update metadata for every new item that you add (I think there is a way to do this for your full movie library too, but may not be realistic if your library is large)
Sweet, I’ve swapped to the legacy agent and so far the problem hasn’t come back but noticed the watchlist button from the movie entry has gone which I use regularly, I assume this is a part of only the new agent.
May need to look at just refreshing the metadata repeatedly for new items, although I’m sure I had older items that used to work just randomly start having the problem so not sure if that would work?