diff --git a/README.md b/README.md index c1b29c4..ad2b958 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ I wrote this script because I was tired of using the excuse that the folder name **model** This simple script shows the hardware model of a raspberry pi. That is all. +**statusPageCheck.sh** +This script is a quick little something to poll my tinystatus page, and if a service is reporting as down, perform an action (such as rebooting the host or restarting the service). + **terminalTweaks.txt** This isn't so much a script as some small quality of life improvements I've made to my WSL Ubuntu 20.04 systems and Ubuntu 20.04 server. Add whichever you like to the end of your .profile and use 'source ~/.profile' to load it immediately. diff --git a/bash/statusPageCheck.sh b/bash/statusPageCheck.sh new file mode 100755 index 0000000..e66a93b --- /dev/null +++ b/bash/statusPageCheck.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Requires tinystatus to be running on the status page. +# If something else is running this script will need to +# be adjusted in order to detect the correct status of +# the services. + +# User configurable settings + +# The domain name of the tinystatus page. +statuspage=status.dismyserver.net +# The name of the service on the tinystatus page. +servicecheck=tempusplexus +# The name of the service locally to perform action on. +servicename=plexmediaserver +# What to do. Currently only restart is supported. +# Anything else here will result in no action. +action=restart + + +# The magic starts here + +# Store whether the service is operational or degraded +isactive=`curl https://${statuspage} 2>/dev/null | grep "${servicecheck}" | egrep -oi "operational|disrupted"` + +# If the service is degraded, perform $action +[ "${isactive}" = "Disrupted" -a "${action}" = "restart" ] && systemctl restart "${servicename}" + +# The magic ends here