Skip to content

Instantly share code, notes, and snippets.

@vchatela
Created November 25, 2020 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vchatela/dcf4b7cac93307da6993b725e0add71f to your computer and use it in GitHub Desktop.
Save vchatela/dcf4b7cac93307da6993b725e0add71f to your computer and use it in GitHub Desktop.
Script to test plex is well running, if not kill it and restart it.
serverURL=monserveur.com
resp=$(curl --write-out %{http_code} --silent --output /dev/null https://$serverURL:32400/plex)
if [ $resp -ne "401" ]; then
#error
echo "Output code is : $resp"
echo "Trying to restart..."
synopkg stop "Plex Media Server"
sleep 5
synopkg start "Plex Media Server"
sleep 10
resp2=$(curl --write-out %{http_code} --silent --output /dev/null https://$serverURL:32400/plex)
if [ $resp2 -ne "401" ]; then
# still error
netstat -nlp | grep :32400
pid=$(netstat -nlp | grep :32400| awk '{print $7}' | grep -o -E '[0-9]+')
echo "PID found : $pid"
kill -9 $pid
echo "Plex should be killed.."
sleep 5
synopkg stop "Plex Media Server"
sleep 5
synopkg start "Plex Media Server"
sleep 10
resp3=$(curl --write-out %{http_code} --silent --output /dev/null https://$serverURL:32400/plex)
if [ $resp3 -ne "401" ]; then
# still error
echo "Service cannot be restarted .."
exit 1
else
echo "Service seems to be restarted after kill -9.."
exit 3
fi
else
# fixed
echo "Service seems to be restarted .."
exit 2
fi
else
#ok
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment