[Very Popular] Restart Plex Server From MyPlex

In the web client, you can do EVERYTHING except that.

Security risk? You can delete a collection, change port, etc.. but no shut down or restart?

All web clients managing a server in those kind of environment have those functions (CouchPotato, SickBeard, MB3, SABNZDB etc...) I was just surprised when I first start using Plex that this option wasn't there in the first place...

Even if "it's not supposed to be needed", for me, it's common sense to have it... (it's not because it's there that you have to use it and it's not just to fix crash or other issues, it could simply be for other maintenance tasks or tests)

So, all that just to simply say +1  :P

So, all that just to simply say +1  :P

Please do say it out loud, and repeat that about 100 times, cuz nobody except you can hear it :P

In order to make a vote count, you'll have to like the first post in this thread

A +1 simply means, that you wasted the time of a lot of people, and causing the needed disk space for hosting this site increase, not to mention backup :rolleyes:

Please read the FAQ pinned on top of this fora about how to vote.

/T

Don't worry, lol, I "liked" the first post  ;)

Thanks for the support people :)

Wouldn’t it be better to have some kind of watchdog and do this automatically when something goes wrong? Usually it is needed to clean up some stalled transcoding job, but if the webserver hangs a remote button isn’t that usefull.

What I do, is restarting the Plex mediaserver every night at 4:00 AM anyway. This is to make sure that when my server hangs, I can still watch movies the next day, even when on holliday.

Jaap

Hi Jaap,

Just wondering, how do you do that? With a script that kills the PMS process and then restarting it? Or do you have a cleaner way of doing it? Because I was planning on implementing this too, but I don't know if straight-forward killing the PMS process can damage stuff..

Killing a process shouldn't damage anything, a kill command is similar to quitting an application.  However killing doesn't always work, basically if a process is unresponsive, then you would use a kill -9 which is similar to force quitting or ending a task, which in most cases will not cause any problems but has the potential.

Just wondering, how do you do that? With a script that kills the PMS process and then restarting it? Or do you have a cleaner way of doing it? Because I was planning on implementing this too, but I don't know if straight-forward killing the PMS process can damage stuff..

I have a small script, that basically kills the process, waits 30 seconds, checks if the process is still visible in a "top", if so, it does a "kill -9". After that, I can start the process again.

I have two reasons for doing that: first is that I want to make sure I can use it the next day, second I can guarantee no changes during my backup. In theory it could leave the database in an inconsistent state, but these things can be fixed easily from the webinterface. It is quite effective when done at the right time (around 4AM), so nobody is using it.

Jaap

Gonna do this too. But what do you mean by "no changes during backup"? Cause a 30 second window for backing up is very tight ;-)

Gonna do this too. But what do you mean by "no changes during backup"? Cause a 30 second window for backing up is very tight ;-)

The 30 seconds is to allow the Plex Media Server to go down gracefully after a stop. What the total script does is:
  • Ask the Plex Server to go down nicely
  • Wait 30 seconds to allow for Plex to get its affairs in order
  • Shoot Plex Down with a Bazooka if it is still active (never happens though, I log this specific type of action in Syslog)
  • Do an RSync of Plex data (usually takes less than a minute) to backup the Plex Media Server
  • Start Plex again
  • Wait 30 seconds to allow Plex to start again
  • Check if it is up again, if not do another killall, start and report to Syslog
Jaap

The 30 seconds is to allow the Plex Media Server to go down gracefully after a stop. What the total script does is:

  • Ask the Plex Server to go down nicely
  • Wait 30 seconds to allow for Plex to get its affairs in order
  • Shoot Plex Down with a Bazooka if it is still active (never happens though, I log this specific type of action in Syslog)
  • Do an RSync of Plex data (usually takes less than a minute) to backup the Plex Media Server
  • Start Plex again
  • Wait 30 seconds to allow Plex to start again
  • Check if it is up again, if not do another killall, start and report to Syslog
Jaap

Any chance you could share your script(s)?

Any chance you could share your script(s)?

No problem. It is run from crontab on a ReadyNAS, so some stuff might be specific.
/etc/init.d/plexserver stop
sleep 30
plexserverpid=""
plexserverpid=`pgrep plexserver`
if [ "$plexserverpid" -gt "0" ]
        then
        kill -9 $plexserverpid
        logger -t dailycleanup "Plex didn't terminate normally on daily restart"
        sleep 30
        fi
rsync -r /c/SOURCE /c/TARGET
/etc/init.d/plexserver start
sleep 30
plexserverpid=""
plexserverpid=`pgrep plexserver`
if [ "$plexserverpid" -gt "0" ]
        then
        echo -e "Plex started nicely"
else
        killall plexserver
        logger -t dailycleanup "Plex didn't start normally on daily restart"
        sleep 30
        /etc/init.d/plexserver start
        fi
Jaap

Yeah, that code isn't very helpfull to me as I'm on Windows haha! :D

But thank you for outlining the steps! Now I know what you meant with the 30 seconds, wasn't clear to me before.

I'll just recreate this stuff for windows for my own benefit, the steps you take are really interchangeable between any OS, it's just the tooling that's different. So thanks!

If anyone is interested just let me know here, I'll post my (windows) batch script over here...

If you look back through the posts there are basic examples, here is the one for windows

for those on windows interested in an alternative method for the time being.  make a batch file using the below as a template

@echo off

C:\Windows\System32 askkill.exe /IM “Plex Media Server.exe” /f

PING 1.1.1.1 -n 1 -w 2000 >NUL

START “Plex” “C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Server.exe”

EXIT

Then use some remote program like unified remote or something similar to run the batch file.

Kills the Media Server

Waits 2 seconds

Starts the Media Server

No problem. It is run from crontab on a ReadyNAS, so some stuff might be specific.

/etc/init.d/plexserver stop
sleep 30
plexserverpid=""
plexserverpid=`pgrep plexserver`
if [ "$plexserverpid" -gt "0" ]
        then
        kill -9 $plexserverpid
        logger -t dailycleanup "Plex didn't terminate normally on daily restart"
        sleep 30
        fi
rsync -r /c/SOURCE /c/TARGET
/etc/init.d/plexserver start
sleep 30
plexserverpid=""
plexserverpid=`pgrep plexserver`
if [ "$plexserverpid" -gt "0" ]
        then
        echo -e "Plex started nicely"
else
        killall plexserver
        logger -t dailycleanup "Plex didn't start normally on daily restart"
        sleep 30
        /etc/init.d/plexserver start
        fi
Jaap

I couldn't get this to work.

I noticed something kills the script as well. In the 'service plexserver stop' some returncode causes the script to abort. It only happens when Plex is running, and only in the "crontab" context, so it is a nasty one to tackle.

I noticed this two days before my hollidays, so i replaced with two seprate cronjobs, one to stop and one to start, but I will investigate further in January...

Jaap

  • 1

+1

Thanks for the support.

I really don't understand why this isn't implemented yet...

I know usually it's not ok to presume it's an easy fix or "a switch to flip" but in this case, very close IMO.

Anyway, in meantime, if I need to restart, I RDP in the server close and reopen PMS from task bar (not that I need to do it often but it's just common sense to be able to do this from Plex/Web)