2010-09-12 22:17:39 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# aixlitesetup
|
|
|
|
# - This script is used to configure the xCAT statelite support
|
|
|
|
# for AIX
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
SL="/.statelite"
|
|
|
|
ROOTDIR="/"
|
|
|
|
MOUNTDIR="$SL/mnt" # where I mount all the trees.
|
|
|
|
PERSISTENT="$SL/persistent"
|
|
|
|
TMPDIR="$SL/tmpdir"
|
|
|
|
DEFAULT="/.default"
|
|
|
|
|
|
|
|
# statelite table files are in "/"
|
|
|
|
# /statelite.table, /litefile.table, /litetree.table
|
|
|
|
STATELITE="/statelite.table"
|
|
|
|
LITEFILE="/litefile.table"
|
|
|
|
LITETREE="/litetree.table"
|
|
|
|
LOG="${ROOTDIR}/${SL}/statelite.log"
|
|
|
|
|
2010-09-13 20:03:15 +00:00
|
|
|
# get this node name from the /etc/niminfo file
|
|
|
|
INFO=`cat /etc/niminfo | grep 'NIM_HOSTNAME'`
|
2010-10-13 16:47:51 +00:00
|
|
|
ME=`echo $INFO | awk -F= '{print $2}' | awk -F. '{print $1}'`
|
2010-09-13 20:03:15 +00:00
|
|
|
|
2010-09-12 22:17:39 +00:00
|
|
|
# check the statelite.table file to see if we have
|
|
|
|
# a persistent dir to mount.
|
|
|
|
ProcessStatelite () {
|
|
|
|
|
|
|
|
for i in `cat $STATELITE | grep -v '^#' | grep $ME`
|
|
|
|
do
|
|
|
|
|
|
|
|
SERVER=`echo $i | awk -F'|' '{print $2}'`
|
|
|
|
TOMNT=`echo $i | awk -F'|' '{print $3}'`
|
|
|
|
|
|
|
|
# /.statelite/tmpdir
|
2010-10-13 16:40:26 +00:00
|
|
|
if [ ! -d ${TMPDIR} ]; then
|
|
|
|
mkdir -m 755 -p ${TMPDIR}
|
|
|
|
fi
|
2010-09-12 22:17:39 +00:00
|
|
|
|
|
|
|
# /.statelite/persistent
|
2010-10-13 16:40:26 +00:00
|
|
|
if [ ! -d ${PERSISTENT} ]; then
|
|
|
|
mkdir -m 755 -p ${PERSISTENT}
|
|
|
|
fi
|
2010-09-12 22:17:39 +00:00
|
|
|
|
|
|
|
# mount 10.2.0.200:/nodedata /.statelite/persistent
|
|
|
|
mount $SERVER:$TOMNT ${PERSISTENT}
|
|
|
|
|
|
|
|
# make a node subdir
|
|
|
|
# /.statelite/persistent/<nodename>
|
2010-10-13 16:40:26 +00:00
|
|
|
if [ ! -d ${PERSISTENT}/${ME} ]; then
|
|
|
|
mkdir -m 755 -p ${PERSISTENT}/${ME}
|
|
|
|
fi
|
2010-10-11 17:35:40 +00:00
|
|
|
|
2010-09-12 22:17:39 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# process the litefile table
|
|
|
|
ProcessLitefile () {
|
|
|
|
for i in `cat $LITEFILE | grep $ME`
|
|
|
|
do
|
|
|
|
type=`echo $i | awk -F'|' '{print $2}'`
|
|
|
|
path=`echo $i | awk -F'|' '{print $3}'`
|
|
|
|
|
|
|
|
FindFile ${path} ${type}
|
|
|
|
done
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
MountTrees () {
|
|
|
|
# ex. /.statelite/mnt
|
2010-10-13 16:40:26 +00:00
|
|
|
if [ ! -d ${MOUNTDIR} ]; then
|
|
|
|
mkdir -m 755 -p $MOUNTDIR
|
|
|
|
fi
|
2010-09-12 22:17:39 +00:00
|
|
|
|
|
|
|
for i in `cat $LITETREE | grep -v '^#' | grep $ME`
|
|
|
|
do
|
|
|
|
|
|
|
|
NODE=`echo $i | awk -F'|' '{print $1}'`
|
|
|
|
SERV=`echo $i | awk -F'|' '{print $2}'`
|
|
|
|
DIR=`echo $i | awk -F'|' '{print $3}'`
|
|
|
|
|
2010-10-13 16:40:26 +00:00
|
|
|
if [ ! -d ${MOUNTDIR}/${SERV}${DIR} ]; then
|
|
|
|
# ex. /.statelite/mnt/10.2.0.200/etc/
|
|
|
|
mkdir -m 755 -p ${MOUNTDIR}/${SERV}${DIR}
|
|
|
|
fi
|
2010-10-11 17:35:40 +00:00
|
|
|
|
2010-09-12 22:17:39 +00:00
|
|
|
MAX=5
|
|
|
|
TRIES=1
|
|
|
|
|
|
|
|
# ex. 10.2.0.200:/etc/ /.statelite/mnt/10.2.0.200/etc/
|
|
|
|
while ! mount $SERV:$DIR ${MOUNTDIR}/${SERV}${DIR}
|
|
|
|
do
|
|
|
|
if [ "$TRIES" = "$MAX" ]
|
|
|
|
then
|
|
|
|
echo "Cannot mount $i." >/dev/console
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
TRIES=`expr $TRIES + 1`
|
|
|
|
S=`expr $RANDOM % 20`
|
|
|
|
echo "Can't mount $SERV:$MNT... Sleeping $S seconds then trying agai
|
|
|
|
n" >/dev/console
|
|
|
|
sleep $S
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ProcessType () {
|
|
|
|
#MOUNT=$1 # where this is (ex. /.statelite/mnt/10.2.0.200/etc/FScfg)
|
|
|
|
#PATH=$2 # file (ex. /etc/FScfg)
|
|
|
|
#TYPE=$3 # type of file (ex. rw)
|
|
|
|
#isChild=$4 # child = 1, parent = 0
|
|
|
|
|
|
|
|
PPATH=`dirname ${2}` # ex. /etc
|
|
|
|
|
|
|
|
case "${3}" in
|
|
|
|
rw)
|
|
|
|
# item is copied from litetree dir or .default location ($1)
|
|
|
|
# into local file
|
|
|
|
|
|
|
|
|
|
|
|
# the local name of the file or directory
|
|
|
|
LOCAL=`echo ${2} | sed -e 's/\/$//'`
|
|
|
|
|
|
|
|
# copy to local file or dir
|
|
|
|
if [ -d ${1} ]; then
|
|
|
|
# if it's a dir then copy all contents to local
|
|
|
|
if [ ! -e ${LOCAL} ]; then
|
2010-10-13 16:40:26 +00:00
|
|
|
mkdir -m 755 -p ${LOCAL}
|
2010-09-12 22:17:39 +00:00
|
|
|
fi
|
|
|
|
if [ "0" -ne `ls -A ${1} | wc -l` ]; then
|
2010-10-13 16:40:26 +00:00
|
|
|
cp -p -r ${1}* ${LOCAL}
|
|
|
|
echo "cp -p -r ${1}* ${LOCAL}" 2>&1 >>$LOG
|
2010-09-12 22:17:39 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
# if file just copy
|
|
|
|
if [ ! -e ${LOCAL} ]; then
|
|
|
|
FDIR=`dirname ${2}`
|
2010-10-13 16:40:26 +00:00
|
|
|
mkdir -m 755 -p ${FDIR}
|
2010-09-12 22:17:39 +00:00
|
|
|
touch ${LOCAL}
|
|
|
|
fi
|
2010-10-13 16:40:26 +00:00
|
|
|
cp -p -r ${1} ${LOCAL}
|
|
|
|
echo "cp -p -r ${1} ${LOCAL}" 2>&1 >>$LOG
|
2010-09-12 22:17:39 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
persistent)
|
|
|
|
# the item is copied to the /.statelite/persistent subdir
|
|
|
|
# from wherever it is found ( $1 above )
|
|
|
|
# the /.statelite/persistent/blah is then mounted
|
|
|
|
# over the local /blah
|
|
|
|
# ex. /.statelite/persistent/compute02/etc
|
|
|
|
if [ ! -d ${PERSISTENT}/${ME}${PPATH} ]; then
|
2010-10-13 16:40:26 +00:00
|
|
|
mkdir -m 755 -p ${PERSISTENT}/${ME}${PPATH}
|
2010-09-12 22:17:39 +00:00
|
|
|
echo "mkdir -p ${PERSISTENT}/${ME}${PPATH}" >>$LOG
|
|
|
|
fi
|
|
|
|
|
|
|
|
# if the file doesn't exist, then copy it over to persistent
|
|
|
|
if [ ! -e ${PERSISTENT}/${ME}${2} ]; then
|
2010-10-13 16:40:26 +00:00
|
|
|
echo "cp -p -r ${1} ${PERSISTENT}/${ME}${2}" >>$LOG
|
|
|
|
cp -p -r ${1} ${PERSISTENT}/${ME}${2} 2>&1 >>$LOG
|
2010-09-12 22:17:39 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
LOCAL=`echo ${2} | sed -e 's/\/$//'`
|
|
|
|
SOURCE=`echo ${PERSISTENT}/${ME}${2}`
|
|
|
|
|
|
|
|
if [ ! -e ${LOCAL} ]; then
|
|
|
|
|
|
|
|
if [ -d ${SOURCE} ]; then
|
|
|
|
# need to create local dir
|
2010-10-13 16:40:26 +00:00
|
|
|
echo "mkdir -m 755 -p ${LOCAL}" >>$LOG
|
|
|
|
mkdir -m 755 -p ${LOCAL}
|
|
|
|
|
2010-09-12 22:17:39 +00:00
|
|
|
else
|
|
|
|
# need to create local file
|
|
|
|
FDIR=`dirname ${2}`
|
2010-10-13 16:40:26 +00:00
|
|
|
if [ ! -d ${FDIR} ]; then
|
|
|
|
mkdir -m 755 -p ${FDIR}
|
|
|
|
fi
|
2010-09-12 22:17:39 +00:00
|
|
|
touch ${LOCAL}
|
|
|
|
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# ex. mount /.statelite/persistent/<nodename>/blah /blah
|
|
|
|
# note: the dir from the statelite table is mounted over
|
|
|
|
# /.statelite/persistent
|
|
|
|
|
|
|
|
# make sure we don't get duplicate mounts
|
|
|
|
umount ${LOCAL}>>$LOG 2>&1
|
|
|
|
|
|
|
|
echo "mount ${SOURCE} ${LOCAL}" >>$LOG
|
|
|
|
mount ${SOURCE} ${LOCAL}>>$LOG 2>&1
|
|
|
|
;;
|
|
|
|
|
|
|
|
ro)
|
|
|
|
# mounted file or dir is overmounted over local version
|
|
|
|
|
|
|
|
# $1 - mounted file or directory or default(?)
|
|
|
|
# $2 - file or dir name
|
|
|
|
|
|
|
|
# ex. /etc/lppcfg
|
|
|
|
LOCAL=`echo ${2} | sed -e 's/\/$//'`
|
|
|
|
|
|
|
|
# ex. /.statelite/mnt/<server>/etc/lppcfg
|
|
|
|
SOURCE=`echo ${1} | sed -e 's/\/$//'`
|
|
|
|
|
|
|
|
if [ ! -e ${LOCAL} ]; then
|
|
|
|
|
|
|
|
if [ -d ${SOURCE} ]; then
|
|
|
|
# need to create local dir
|
2010-10-13 16:40:26 +00:00
|
|
|
echo "mkdir -m 755 -p ${LOCAL}" >>$LOG
|
|
|
|
mkdir -m 755 -p ${LOCAL}
|
2010-09-12 22:17:39 +00:00
|
|
|
else
|
|
|
|
# need to create local file
|
2010-10-13 16:40:26 +00:00
|
|
|
GDIR=`dirname ${2}`
|
|
|
|
if [ ! -d ${GDIR} ]; then
|
|
|
|
mkdir -m 755 -p ${GDIR}
|
|
|
|
fi
|
2010-09-12 22:17:39 +00:00
|
|
|
touch ${LOCAL}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
# make sure we don't get duplicate mounts
|
|
|
|
umount ${LOCAL}>>$LOG 2>&1
|
|
|
|
|
|
|
|
echo "mount -o ro ${SOURCE} ${LOCAL}" >>$LOG 2>&1
|
|
|
|
# ex. mount -o /.statelite/mnt/<server>/etc/lppcfg /etc/lppcfg
|
|
|
|
mount -o ro ${SOURCE} ${LOCAL}>>$LOG 2>&1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FindFile () {
|
|
|
|
# $1 = Pathname to locate
|
|
|
|
# $2 = Type of file
|
|
|
|
# $3 = 0 or 1: 0 means parent, 1 means child
|
|
|
|
path=$1
|
|
|
|
type=$2
|
|
|
|
isChild=$3
|
|
|
|
FOUND=0
|
|
|
|
|
|
|
|
# this assumes the dir are already in priority order
|
|
|
|
for i in `cat $LITETREE | grep -v '^#' | grep $ME`
|
|
|
|
do
|
|
|
|
|
|
|
|
SERVER=`echo $i | awk -F'|' '{print $2}'`
|
|
|
|
DIR=`echo $i | awk -F'|' '{print $3}'`
|
2010-10-07 16:19:07 +00:00
|
|
|
SRC=`echo ${MOUNTDIR}/${SERVER}${DIR}${path} | sed -e 's/\/\//\//'`
|
2010-09-12 22:17:39 +00:00
|
|
|
|
2010-10-13 16:40:26 +00:00
|
|
|
# ex. /.statelite/mnt/10.2.0.200/etc/FScfg
|
2010-09-12 22:17:39 +00:00
|
|
|
if [ -e ${SRC} ]; then
|
|
|
|
|
|
|
|
FOUND=1
|
|
|
|
ProcessType ${SRC} ${path} ${type} ${isChild}
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Default behavior is to get from the image
|
|
|
|
if [ "$FOUND" = "0" ]; then
|
|
|
|
|
|
|
|
if [ -e "${DEFAULT}${path}" ]; then
|
|
|
|
|
|
|
|
|
|
|
|
ProcessType ${DEFAULT}${path} ${path} ${type} ${isChild}
|
|
|
|
else
|
|
|
|
|
|
|
|
echo "Could not find ${path} in defaults or any other place" >/dev/console
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# Start / MAIN / main
|
|
|
|
###########################################################################
|
|
|
|
|
|
|
|
# mount the persistent dir - if provided
|
|
|
|
ProcessStatelite
|
|
|
|
|
|
|
|
# mount all the dirs from the litetree table.
|
|
|
|
MountTrees
|
|
|
|
|
|
|
|
# process the litefile table
|
|
|
|
ProcessLitefile
|
|
|
|
|
|
|
|
# Unmount dirs no longer needed - TBD
|
|
|
|
#UnmountTrees
|
|
|
|
|
|
|
|
exit 0
|