Skip to content

Instantly share code, notes, and snippets.

@evenwebb
Created April 12, 2018 17:02
Show Gist options
  • Save evenwebb/918fa882222228a019d117d8123c0134 to your computer and use it in GitHub Desktop.
Save evenwebb/918fa882222228a019d117d8123c0134 to your computer and use it in GitHub Desktop.
Check Plex Server Status
#!/bin/bash
#name=Plex Media Server check and restart
#description=This script will restart PLEX if it does not respond after two attempts.
#arrayStarted=true
dockerid=$(docker ps -aqf "name=Plex")
if [ "$dockerid" == "" ]; then
echo "ERR $(date -Is) - Could not get a docker id for docker name \"Plex\"."
exit 1;
fi
# Do not check between 1:55am to 2:30am
currentTime=`date +"%H%M%S"`
if [[ ! ( "$currentTime" < "015500" || "$currentTime" > "023000" ) ]]; then
exit 0;
fi
firstcheck=$((curl -sSf -m30 http://server:port/web/) 2>&1)
if [ "$firstcheck" != "" ]; then
echo "WRN $(date -Is) - Plex did not respond in first check, waiting 15 seconds.."
sleep 15
secondcheck=$((curl -sSf -m30 http://server:port/web/) 2>&1)
if [ "$secondcheck" != "" ]; then
echo "WRN $(date -Is) - Plex did not respond in second check either, restarting docker container."
echo "INF $(date -Is) - Stopping docker $dockerid."
docker stop $dockerid
echo "INF $(date -Is) - Waiting 15 seconds.."
sleep 15
echo "INF $(date -Is) - Starting docker $dockerid."
docker start $dockerid
else
echo "INF $(date -Is) - Plex docker container responded on second attempt."
fi
else
echo "INF $(date -Is) - Plex docker container responded on first attempt."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment