Skip to content

Instantly share code, notes, and snippets.

@flatlinebb
Last active January 15, 2019 21:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flatlinebb/6979968610e332496319264e4fb16ce4 to your computer and use it in GitHub Desktop.
Save flatlinebb/6979968610e332496319264e4fb16ce4 to your computer and use it in GitHub Desktop.
Checks the Pulseway service and restarts it if not running. Logs to /var/log/pulseway.log
#!/bin/bash
### Pulseway Service Check ###
### Log file location: /var/log/pulseway.log
### Add to crontab for hourly checks at half-past the hour, with no console output:
### 30 * * * * /root/pulseway-service-check.sh > /dev/null 2>&1
### This way, crontab doesn't try to email the result of the job
# Create $variable with the current service status
STATUS=`systemctl show -p SubState --value pulseway`
# For older versions of systemd, skip the "--value"
#STATUS=`systemctl show -p SubState pulseway`
# Create $variable for the log file location
LOG=/var/log/pulseway.log
# Echo $variable value for debugging
# Leave commented out for production
#echo $STATUS
# If status is not "running", then echo message, then restart the service
# If status is "running", then just log it and exit
#if [ "$STATUS" != "SubState=running" ]; then
if [ "$STATUS" != "running" ]; then
echo "Pulseway Service is not Running! $(date)" | tee -a $LOG 2>&1
echo "Restarting Pulseway service" | tee -a $LOG 2>&1
systemctl restart pulseway | tee -a $LOG 2>&1
echo "Current Pulseway service status: " | tee -a $LOG 2>&1
systemctl status pulseway | tee -a $LOG 2>&1
echo $STATUS | tee -a $LOG 2>&1
else
echo "Pulseway Service is currently Running! $(date)" | tee -a $LOG 2>&1
echo $STATUS | tee -a $LOG 2>&1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment