From 6bd079921d6a8f319ba24b8ab448c1da9c4bf3fe Mon Sep 17 00:00:00 2001 From: yujian Date: Fri, 2 Jun 2006 10:18:46 +0000 Subject: [PATCH] b=9853 Script to create mon.cf file for Heartbeat. --- lustre/scripts/lc_mon.sh | 139 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100755 lustre/scripts/lc_mon.sh diff --git a/lustre/scripts/lc_mon.sh b/lustre/scripts/lc_mon.sh new file mode 100755 index 0000000..ac4be84e7 --- /dev/null +++ b/lustre/scripts/lc_mon.sh @@ -0,0 +1,139 @@ +#!/bin/sh + +# Given one or more Lustre objects, create a mon configuration file +# naming the mon watches based on the Lustre object names +# For each Lustre object, the script will create two mon watches +# The first watch sets a trap, and the second watch clears the +# trap if Lustre is healthy. + +# This may be more fun in Perl due to the need to support a list +# of objects + +# (plus we could use a Perl format for this goop) + +MONBASEDIR=${MONBASEDIR:-/usr/local/lib/mon} +MONCFGDIR=${MONCFGDIR:-/etc/mon} +TD=`date +%y_%m%d_%S` +TMPMONCFG=${TD}-mon.cfg +# Determines how often we will check Lustre health +CHECKINTERVAL="3m" +# Determines how quickly we must clear the trap +TRAPINTERVAL="6m" +ALERTSCRIPT=${ALERTSCRIPT:-"fail_lustre.alert"} +TRAPSCRIPT=${TRAPSCRIPT:-"lustre.mon.trap"} + +# We will assume all inputs are Lustre objects +# file locations and timeouts correct to taste +# Correct to taste +print_header() { + cat >> $TMPMONCFG <<-EOF + cfbasedir = $MONCFGDIR + alertdir = $MONBASEDIR/alert.d + mondir = $MONBASEDIR/mon.d + statedir = $MONBASEDIR/state.d + logdir = $MONBASEDIR/log.d + dtlogfile = $MONBASEDIR/log.d/downtime.log + maxprocs = 20 + histlength = 100 + randstart = 60s + authtype = getpwnam +EOF +} + +# Tabs should be preserved in the config file +# $1 object name +# we do not set a period, it is assumed monitor is always active + +print_trap_rec() { + cat >> $TMPMONCFG <> $TMPMONCFG < -n -o -o ...." + echo "Creates the /etc/mon/mon.cf file to monitor Lustre objects" + exit 1 +} + + +# Start of script + +if [ $# -eq 0 ];then + usage +fi + +# This script should work for any number of hosts +# +HOSTCNT=0 +OBJCNT=0 + +declare -a HOSTS +declare -a OBJS + +while getopts "n:o:" opt; do + case $opt in + n) HOSTS[HOSTCNT]=$OPTARG + HOSTCNT=$(( HOSTCNT + 1 )) + ;; + o) OBJS[OBJCNT]=$OPTARG + OBJCNT=$(( OBJCNT + 1 )) + ;; + *) usage + ;; + esac +done + +echo "Found $HOSTCNT hosts" +echo "Found $OBJCNT Lustre objects" + +# First create the host groups +# we assume +# each object will have two watches defined +# each object hostgroup will have all objects + +# Create the file with the declared goop +print_header + +for obj in ${OBJS[@]} +do + echo "hostgroup ${obj}-obj ${HOSTS[@]}" >> $TMPMONCFG + echo "hostgroup ${obj}-mon ${HOSTS[@]}" >> $TMPMONCFG + echo "#" >> $TMPMONCFG +done + +# create the monitors + +for obj in ${OBJS[@]} +do + print_trap_send $obj + print_trap_rec $obj +done + +echo "Mon config completed - new mon config is $TMPMONCFG" +exit 0 \ No newline at end of file -- 1.8.3.1