Plex self healing restart script.


Recommended Posts

  I looked all over for a script that does this and couldn't find it.  If this is a double post, my apologies as I can't imagine I'm the first one to raise this topic.

 

I wanted to share my script that checks if Plex is taking connections on it's default port and attempts to cycle it if not.

 

You would have to place it in the root of your flash drive otherwise known as /boot.

 

This would be run as an hourly cron job or w/e you prefer.

 

To have this change persist across reboots, you must add this to your go file.

 

crontab -l > /tmp/cron; echo '#Run Hourly Plex Connection Check' >> /tmp/cron; echo '30 * * * * /boot/PlexCheck' >>/tmp/cron; crontab /tmp/cron; rm /tmp/cron

 

The script echo's the results to the console which I prefer however you could get rid of it by adding &>/dev/null to the end of the cron job.

 

The script could also be easily edited to have the echo's append to a file as a log that can be checked.  I prefer the console.

 

So far my go file and script have been tested and working as expected.

 

In my experience, plex may indeed be running, however it will stop taking connections from time to time.  This method will catch both conditions where plex is not running or plex is running but not responding to connections properly and attempt to resolve it. 

 

Script attached.  You will need to drop the .txt extension when it is placed on your flash drive.

PlexCheck.txt

Link to comment

  Also here's a version that outputs to a log file you can check to make sure it's running and what the results of the run are. 

 

The log is /var/PlexCheckLog

 

This is the volital file system that exists in memory and should clear each reboot.  I doubt anyone's uptime would be long enough for the log size to ever be a problem so i decided not to add any log rotation or clean up apart of the script.

 

I didn't make seance to put the log on the flash or cache disk.

 

You would be able to view the log when logged into the sever as shown below.

 

root@Tower:/var# cat ./PlexCheckLog

Wed Dec 17 13:52:09 CST 2014 Plex appears to be accepting connections!

Wed Dec 17 14:30:01 CST 2014 Plex appears to be accepting connections!

Wed Dec 17 15:30:01 CST 2014 Plex appears to be accepting connections!

root@Tower:/var# tail -10 ./PlexCheckLog

Wed Dec 17 13:52:09 CST 2014 Plex appears to be accepting connections!

Wed Dec 17 14:30:01 CST 2014 Plex appears to be accepting connections!

Wed Dec 17 15:30:01 CST 2014 Plex appears to be accepting connections!

 

 

 

 

 

 

PlexCheckv2.txt

Link to comment

Yeah I could try that.  It's humanly possible Plex is doing some heavy streaming or the system is loaded and fail an attempt here and there.  That's certainly true with some of my server up SSH port checks to find downed systems at work that use almost the same logic.  I'll update it later.

 

 

 

 

 

 

Link to comment

  Here is my script that adds on 3 retry attempts before restarting plex.

 

I've tested it and it appears to be working.  I tried to load the box to test my loaded system condition but that's something a little hard to simulate.  Far as I can tell, it should work should that condition arise.  Additional logging was sent to /var/PlexCheckLog.

 

You will either have to rename the script to match the entry in the go file or edit the go file to reflect the script name "PlexCheckv3".

 

Logging will now look something like this., That first line is another cron job that cycles Plex at Night anyway.  This is a highly paranoid check, not really necessary.

 

Thu Dec 18 04:00:20 CST 2014 Plex was restarted for nightly reboot and appears to be taking connections

Thu Dec 18 04:30:01 CST 2014 Plex appears to be accepting connections!

Thu Dec 18 05:30:02 CST 2014 Plex appears to be accepting connections!

Thu Dec 18 06:30:01 CST 2014 Plex appears to be accepting connections!

Thu Dec 18 07:30:01 CST 2014 Plex appears to be accepting connections!

Thu Dec 18 08:30:42 CST 2014 Plex appears to be accepting connections!

Thu Dec 18 09:30:01 CST 2014 Plex appears to be accepting connections!

Thu Dec 18 10:08:15 CST 2014 Plex is not accepting connections, retrying

Thu Dec 18 10:08:25 CST 2014 Plex is not accepting connections, retrying

Thu Dec 18 10:08:35 CST 2014 Plex is not accepting connections, retrying

Thu Dec 18 10:09:57 CST 2014 Plex was restarted and appears to now be accepting connections

Thu Dec 18 10:15:27 CST 2014 Plex appears to be accepting connections!

Thu Dec 18 10:15:49 CST 2014 Plex appears to be accepting connections!

Thu Dec 18 10:16:30 CST 2014 Plex appears to be accepting connections!

Thu Dec 18 10:17:48 CST 2014 Plex is not accepting connections, retrying

Thu Dec 18 10:12:17 CST 2014 Plex is not accepting connections, retrying

Thu Dec 18 10:12:27 CST 2014 Plex is not accepting connections, retrying

Thu Dec 18 10:13:02 CST 2014 Plex was restarted and appears to now be accepting connections

Thu Dec 18 10:21:58 CST 2014 Plex is not accepting connections, retrying

Thu Dec 18 10:22:08 CST 2014 Plex is not accepting connections, retrying

Thu Dec 18 10:22:37 CST 2014 Plex was restarted and appears to now be accepting connections

Thu Dec 18 10:30:01 CST 2014 Plex appears to be accepting connections!

PlexCheckv3.txt

Link to comment
  • 2 weeks later...
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.