You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Princeton/failover/failover.sh

74 lines
2.5 KiB
Bash

#!/bin/sh
#
# Nagios XI failover for Princeton University
#
# Initial version written by:
# Eric Loyd (eloyd@everwatch.global)
# EverWatch Global, Inc.
PATH=/usr/sbin:/sbin:/usr/bin:/bin
#primary="nagiosxi-p.princeton.edu"
#secondary="nagiosxi-f.princeton.edu"
primary=""
secondary=""
synconly="false"
syncname="sync"
extraCmd=""
hostname=`/bin/hostname`
. ./colors.sh
while [ -n "$1" ]; do
case "$1" in
-H | --hostname) hostname="$2"; shift 2;;
-S | --secondary) secondary="$2"; shift 2;;
-P | --primary) primary="$2"; shift 2;;
-n | --sync-name) syncname="$2"; shift 2;;
-s | --sync-only) synconly="true"; shift 1;;
*) extraCmd="$extraCmd $1"; shift 1;;
esac
done
[ -z "$hostname" ] && warning "Invalid hostname." && exit 2
do_nothing() {
warning "We are not the primary or secondary. Doing nothing."
exit 1
}
do_primary() {
verbose "We are the primary. Creating package to send to secondary."
./rsync_xi.sh --prepend ${syncname} --primary "${primary}" --secondary "${secondary}" $extraCmd
if [ -r "/usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css.primary" -a -w "/usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css" ]; then
verbose "Copying local gradient files"
cp /usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css.primary /usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css
fi
}
do_secondary() {
verbose "We are the secondary. Expanding package from the primary."
syncfile=$(basename `ls -tr1 /store/backups/nagiosxi/${syncname}* | tail -1`)
[ -z "$syncfile" ] && error "No sync file ($syncfile) found." && exit 2
./rsync_xi.sh --primary "${primary}" --secondary "${secondary}" --file "/store/backups/nagiosxi/$syncfile"
if [ $? -eq 0 ]; then
verbose "Ensuring Nagios services are stopped because we are the secondary"
sleep 2
/home/nagios/bin/nagios_startstop.sh stop
if [ -r "/usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css.secondary" -a -w "/usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css" ]; then
cp /usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css.secondary /usr/local/nagiosxi/html/includes/components/custom-includes/css/header-gradient.css
fi
rm -f ${syncfile}
fi
}
case "$hostname" in
$primary) do_primary;;
$secondary) do_secondary;;
*) do_nothing
esac
exit 0