Skip to content

Instantly share code, notes, and snippets.

@un33k
Last active April 6, 2024 13:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save un33k/643710 to your computer and use it in GitHub Desktop.
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.
#!/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
#!/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