Last active
January 15, 2019 21:21
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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