Last active
April 6, 2024 13:38
-
-
Save un33k/643710 to your computer and use it in GitHub Desktop.
Plex on OSX often falls into a tight loop and consumes %100 of the CPU. This watchdog is to restart Plex to avoid running the CPU hot for an extended period of time.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
PLEX_APP='/Applications/Plex Home Theater.app/Contents/MacOS/Plex Home Theater' | |
COUNT=0 | |
PLEX_CPU=0 | |
LOOP=1 | |
while [ $LOOP -le 14 ] ; do | |
PLEX_CPU=`ps aux | grep "$PLEX_APP" | awk '{print $3}' | head -n 1` | |
PLEX_CPU=`osascript -e "round($PLEX_CPU)"` | |
#echo $PLEX_CPU | |
if [ $PLEX_CPU -gt 95 ]; then | |
echo Value of count is: $COUNT | |
let COUNT=COUNT+1 | |
fi | |
if [ $COUNT -gt 12 ]; then | |
#echo Must kill Plex: $COUNT | |
PLEX_PID=`ps aux | grep "$PLEX_APP" | awk '{print $2}' | head -n 1` | |
kill -9 $PLEX_PID > /dev/null 2>&1 | |
sleep 10 | |
"$PLEX_APP" > /dev/null 2>&1 & | |
COUNT=0 | |
fi | |
sleep 4 | |
LOOP=`expr $LOOP + 1` | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
PLEX_APP='/Applications/Plex Home Theater.app/Contents/MacOS/Plex Home Theater' | |
PLEX_PID=`ps aux | grep "$PLEX_APP" | awk '{print $2}' | head -n 1` | |
kill -9 $PLEX_PID > /dev/null 2>&1 | |
sleep 10 | |
"$PLEX_APP" > /dev/null 2>&1 & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment