sh 检查Pulseway服务并在未运行时重新启动它。登录到/var/log/pulseway.log

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 检查Pulseway服务并在未运行时重新启动它。登录到/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

以上是关于sh 检查Pulseway服务并在未运行时重新启动它。登录到/var/log/pulseway.log的主要内容,如果未能解决你的问题,请参考以下文章