This repository has been archived by the owner on Jan 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d54df9
commit a37afb6
Showing
7 changed files
with
193 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!/bin/bash | ||
# +--------------------------------------------------------------------+ | ||
# EFA Monitor cron | ||
# Version 20151212 | ||
# +--------------------------------------------------------------------+ | ||
# Copyright (C) 2012~2015 http://www.efa-project.org | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# +--------------------------------------------------------------------+ | ||
|
||
# +--------------------------------------------------------------------+ | ||
# EFA Monitor Cron Script | ||
# Set to run at a regular interval (i.e. every minute) | ||
# +--------------------------------------------------------------------+ | ||
|
||
# +--------------------------------------------------------------------+ | ||
# Configurable Variables | ||
# +--------------------------------------------------------------------+ | ||
MaxRestartAttempts=3 | ||
# Monitored Service Array (daemon=sysv) | ||
MonitoredServices=("mysqld=mysqld" "MailScanner=MailScanner" "qmgr=postfix" "master=postfix" "pickup=postfix" "httpd=httpd" "miniserv.pl=webmin" "clamd=clamd" "unbound=unbound" "saslauthd=saslauthd" "sqlgrey=sqlgrey" "dccifd=adcc") | ||
# Enable restart expiry (1 day) | ||
RestartExpiry=1 | ||
AttemptsFile="/var/EFA/EFAmonitor" | ||
ADMINEMAIL="`cat /etc/EFA-Config | grep ADMINEMAIL | sed 's/.*://'`" | ||
MAILFROM="$ADMINEMAIL" | ||
MAILTO="$ADMINEMAIL" | ||
MAILSUBJECT="EFA Monitor ALERT" | ||
SENDMAIL="/usr/lib/sendmail" | ||
TMPMAIL="/tmp/tempmail" | ||
|
||
# +--------------------------------------------------------------------+ | ||
|
||
# +--------------------------------------------------------------------+ | ||
# Check Services Function | ||
# +--------------------------------------------------------------------+ | ||
function CheckServices() { | ||
for monitoredService in ${MonitoredServices[@]}; do | ||
# Load attempts, or create if not present | ||
[[ -x $AttemptsFile ]] || ( touch $AttemptsFile ) | ||
mDaemon=$(echo $monitoredService | awk -F'=' '{print $1}') | ||
mService=$(echo $monitoredService | awk -F'=' '{print $2}') | ||
serviceCheck=$(ps -C $mDaemon --no-heading) | ||
dateStamp=$(date +%Y%m%d) | ||
if [[ -z "$serviceCheck" ]]; then | ||
# Service is not running! | ||
# Check # of attempts, if present | ||
serviceAttempts=$(grep -e "^$mService=" $AttemptsFile | awk -F'=' '{print $2}') | ||
if [[ -z "$serviceAttempts" || "$serviceAttempts" -le "$MaxRestartAttempts" ]]; then | ||
# Start Service | ||
/sbin/service $mService start | ||
# Increment restart attempts | ||
attemptCount=$(grep -e "^$mService=" $AttemptsFile | awk -F'=' '{print $2}') | ||
if [[ -z $attemptCount ]]; then | ||
attemptCount=1 | ||
echo "$mService=$attemptCount" >> $AttemptsFile | ||
echo "date$mService=$dateStamp" >> $AttemptsFile | ||
else | ||
attemptCount=$(($attemptCount+1)) | ||
sed -i "/^$mService=/ c\\$mService=$attemptCount" $AttemptsFile | ||
sed -i "/^date$mService=/ c\date$mService=$dateStamp" $AttemptsFile | ||
fi | ||
AlertOnFailure | ||
fi | ||
else | ||
if [[ "$RestartExpiry" -eq "1" ]]; then | ||
checkDate=$(grep -e "^date$mService=" $AttemptsFile | awk -F'=' '{print $2}') | ||
|
||
if [[ -n "$checkDate" && "$checkDate" -ne "$dateStamp" ]]; then | ||
sed -i "/^$mService=/d" $AttemptsFile | ||
sed -i "/^date$mService=/d" $AttemptsFile | ||
fi | ||
fi | ||
fi | ||
done | ||
} | ||
|
||
# +--------------------------------------------------------------------+ | ||
# Alert On Failure Notification Function | ||
# +--------------------------------------------------------------------+ | ||
function AlertOnFailure() { | ||
logger -p "daemon.alert" "EFA Monitor ALERT: Service $mService down and restarted ( $attemptCount attempts in past day, max attempts is $MaxRestartAttempts )" | ||
echo "From: $MAILFROM" > $TMPMAIL | ||
echo "To: $MAILTO" >> $TMPMAIL | ||
echo "Reply-To: $MAILFROM" >> $TMPMAIL | ||
echo "Subject: $MAILSUBJECT" >> $TMPMAIL | ||
echo "" >> $TMPMAIL | ||
echo "Service $mService down and restarted ( $attemptCount attempts in past day, max attempts is $MaxRestartAttempts )" >> $TMPMAIL | ||
echo "" >> $TMPMAIL | ||
echo "Please examine your EFA logs and resources to determine cause of failure." >> $TMPMAIL | ||
cat $TMPMAIL | $SENDMAIL -t | ||
rm $TMPMAIL | ||
} | ||
# +--------------------------------------------------------------------+ | ||
|
||
# +--------------------------------------------------------------------+ | ||
# Main Function | ||
# +--------------------------------------------------------------------+ | ||
CheckServices |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# +---------------------------------------------------+ | ||
# Function to toggle EFA Monitor for Maintenance | ||
# +---------------------------------------------------+ | ||
func_maintenance-mode() { | ||
func_echo-header | ||
echo -e "$green[EFA]$clean - Maintenance Mode" | ||
echo -e "" | ||
echo -e "$green[EFA]$clean This option will toggle EFA Monitor to allow for Maintenance" | ||
echo -e "" | ||
[[ -f /etc/cron.d/EFA-Monitor.cron ]] && modeStatus="0" || modeStatus="1" | ||
|
||
if [[ "$modeStatus" -eq "0" ]]; then | ||
echo -en "$green[EFA]$clean : Enter EFA Maintenance Mode? (y/N):" | ||
read MAINTENANCE | ||
|
||
FLAG=1 | ||
while [ $FLAG -eq 1 ] | ||
do | ||
if [[ $MAINTENANCE =~ ^[yY]$ ]]; then | ||
mv -f /etc/cron.d/EFA-Monitor.cron /var/EFA | ||
echo -e "" | ||
echo -e "$green[EFA]$clean Maintenance mode is $green ENABLED $clean" | ||
echo -e "" | ||
FLAG=0 | ||
elif [[ -z "$MAINTENANCE" || $MAINTENANCE =~ ^[nN]$ ]]; then | ||
echo -e "" | ||
echo -e "$green[EFA]$clean No action taken" | ||
else | ||
echo -e "$red[ERROR]$clean Invalid input | ||
echo -en "$green[EFA]$clean : Enter EFA Maintenance Mode? (y/N):" | ||
read MAINTENANCE | ||
fi | ||
done | ||
else | ||
echo -en "$green[EFA]$clean : Exit EFA Maintenance Mode? (Y/n):" | ||
read MAINTENANCE | ||
|
||
FLAG=1 | ||
while [ $FLAG -eq 1 ] | ||
do | ||
if [[ -z "$MAINTENANCE" || $MAINTENANCE =~ ^[yY]$ ]]; then | ||
[[ -f /var/EFA/EFA-Monitor.cron ]] && ( mv -f /var/EFA/EFA-Monitor.cron /etc/cron.d ) || ( echo "* * * * * root /usr/sbin/EFA-Monitor-cron" > /etc/cron.d/EFA-Monitor.cron ) | ||
echo -e "" | ||
echo -e "$green[EFA]$clean Maintenance mode is $green DISABLED $clean" | ||
echo -e "" | ||
FLAG=0 | ||
elif [[ $MAINTENANCE =~ ^[nN]$ ]]; then | ||
echo -e "" | ||
echo -e "$green[EFA]$clean No action taken" | ||
else | ||
echo -e "$red[ERROR]$clean Invalid input | ||
echo -en "$green[EFA]$clean : Exit EFA Maintenance Mode? (Y/n):" | ||
read MAINTENANCE | ||
fi | ||
done | ||
fi | ||
pause | ||
|
||
} | ||
# +---------------------------------------------------+ |
This file contains 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
This file contains 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
This file contains 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