Check for Plex before rebooting

I previously wrote a rudimentary script and post where I wanted to reboot my htpc if I was unable to access the internet.  That has been working fine and rebooted the system more than a few times.  But I’ve learned that I don’t necessarily want to reboot if I’m using the system inside my network.  Like if Plex is actively serving content, don’t reboot.

At any point in time, the Plex Media Server has a few processes running.  That’s just how it works.  So I only want to make note of this if any one of those processes is in the top 5 list of CPU consumers.

NOTE:  this number is arbitrary and I picked 5 because I watched the processes for a few minutes while I was watching a video and Plex lingered within the top 5…this could probably be tweaked, but I’m just estimating here.  I found that there were some plex processes in the top 10 even if it wasn’t doing anything.

So the following command is very generic and will tell me if any of the top 5 processes have “plex” in their name or even if the plex user owns them.  There’s a chance that I should restrict this more, but again, I’m not attempting to land a rover on Mars.  Close is good enough in this instance.

ps -Ao pcpu,user,args --no-headers --sort=-pcpu |\
  head -n5 | grep -i plex

I have added this test to my check_vpn.sh script.  I know that this is not the way that git or github is intended to be used, but I grab the script from github via:

wget --no-verbose \https://raw.githubusercontent.com/ilearnedthisthehardway/network-verification-scripts/master/check_vpn.sh

And then I ensure my crontab is using the correct file:

*/10 * * * * /root/check_vpn.sh

There we have it.  I will check the log file occasionally to see if this is working as intended.


REFERENCES:

 

1 Comment for “Check for Plex before rebooting”

Leave a Reply

Your email address will not be published. Required fields are marked *