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的主要内容,如果未能解决你的问题,请参考以下文章

所以我想在崩溃时重新启动nodejs服务器

如何确保程序正在运行并在需要时重新启动它?

sh mysql自动检查运行状态自动重新启动脚本邮件提醒

检查 ufw 状态并在未激活时发送 Prometheus 警报

如何使用cron检查程序是否在后台运行,并在需要时启动它?

windows 下 mysql 服务不能启动出现 "本地计算机上的mysql服务启动后停止,某些服务在未由其它服务或程序使用时将自动停"