#!/bin/sh
#
# Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like. Any license provided herein, whether implied or
# otherwise, applies only to this software file. Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
#
# Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
# Mountain View, CA 94043, or:
#
# http://www.sgi.com
#
# For further information regarding this notice, see:
#
# http://oss.sgi.com/projects/GenInfo/NoticeExplan
#
# fsinstall
#
# Linux FailSafe Installation Script
#
# Args:
# $1 location of the Linux FailSafe bin RPMS (optional)
#
#
#
# List of Rpms to be installed (order matters)
FS_RPMS_LIST="cluster_admin cluster_services failsafe"
# Default value for location of the FailSafe bin RPMS
FS_RPMS_DIR=./dist/RPMS/i386
# List of external packages that MUST be installed for running Linux FS
RPMS_REQUIRED="sysadm_base-lib"
# List of tools that MUST be installed for running Linux FS
TOOLS_REQUIRED="/sbin/portmap"
# Misc ports used by Linux FailSafe daemons.
# These ports are used to update /etc/services
CMSD_PORT=17000
CRSD_PORT=17001
GCD_PORT=17002
CAD_PORT=17003
# Filenames used to determine on which distribution
# Linux FailSafe is being installed.
# Currently only SuSE and RH are detected.
SUSE_DISTRIB_ID=/etc/SuSE-release
RH_DISTRIB_ID=/etc/redhat-release
# Path for some Linux FailSafe tools
FS_BIN_DIR=/usr/lib/failsafe/bin
#
# usage
#
# Print usage for fsinstall on stdout
#
# Args:
# None
#
function usage()
{
echo -e "\nUsage: $0 [rpm_dir]\n"
echo -e "\trpm_dir: location of the binary rpms to be installed.\n"
return 0
}
#
# fatal_error
#
# Exit from script in error
#
# Args:
# $1 error description
#
function fatal_error()
{
echo "Fatal Error: $1"
echo "Exiting from fsinstall."
exit -1
}
#
# check_package_is_installed()
#
# Check that an rpm package is correctly installed
#
# Args:
# $1 package name
#
# Return value:
# 0 if success
# exit from script in case of failure
#
function check_package_is_installed()
{
echo -e " Package $1\t\t\c"
rpm -q $1 > /dev/null 2>&1
if [ $? != 0 ]
then
echo -e " [ NOK ]"
fatal_error "Package $1 not found."
else
echo -e " [ OK ]"
return 0
fi
}
#
# check_tool_is_installed()
#
# Check that a file is installed on the local machine
#
# Args:
# $1 Directory/filename
#
# Return value:
# 0 if success
# exit from script in case of failure
#
function check_file_is_installed()
{
echo -e " File $1\t\t\c"
if [ ! -f $1 ]; then
which `basename $1`
if [ $? -ne 0 ]; then
echo -e " [ NOK ]"
fatal_error "File $1 not found."
fi
fi
echo -e " [ OK ]"
return 0
}
#
# create_init_level_symlink
#
# Create symlink in init runlevel directories
#
# Args:
# $1 script name
# $2 run level
# $3 order = [S|K][0..9][0..9]
#
# Return value:
# 0 if success
# -1 in case of failure
#
# Ex.:
# create_init_level_symlink myscript 2 S25
#
function create_init_level_symlink()
{
echo " Creating link /etc/rc.d/rc$2.d/$3$1"
cd /etc/rc.d/rc$2.d
# if link doesn't already exist, create it.
if [ ! -f $3$1 ]
then
ln -s ../init.d/$1 $3$1
fi
cd -
return 0
}
#
# add_service
#
# Add an entry in /etc/services file
#
# Args:
# $1 service name
# $2 port number
# $3 protocol type
# $4 optional comment
#
# Return value:
# 0 if success
# exit from script in case of failure
#
# Ex.:
# add_service myservice 7000 tcp
#
function add_service()
{
# check service is not already defined
grep $1 /etc/services >/dev/null 2>&1
if [ $? != 0 ]
then
echo " Adding service $1, port $2, protocol $3 to /etc/services"
# check port is not already assigned
grep "\W$2\/" /etc/services >/dev/null 2>&1
if [ $? = 0 ]
then
echo " Conflict: port $2 already assigned."
echo " Modify the fsinstall script to use a "
echo " different port number than $2 for service $1"
echo " Make sure port number are consistent across your cluster."
fatal_error "Port number conflict in /etc/services."
else
# Add line in /etc/services
echo -e "$1\t$2/$3\t# $4" >> /etc/services
fi
else
# check port is the same
entry=`grep $1 /etc/services`
echo ${entry} | grep "\W$2\/" >/dev/null 2>&1
if [ $? != 0 ]
then
echo " Service $1 already defined in /etc/service but with a different port number"
echo " Clean-up your /etc/services file and re-execute fsinstall."
fatal_error "Port number inconsistency in /etc/services."
else
echo " Service $1 was already defined in /etc/service with port $2"
fi
fi
return 0
}
#################
# #
# MAIN #
# #
#################
if [ $# -gt 1 ]; then
usage
fatal_error "Bad usage."
fi
echo -e "\n**** FailSafe Installation BEGIN ****\n"
# Checking rpms and misc files required by Linux FailSafe are installed
#
# NOTE: These checks could be done by the rpm themselves.
# this should be an improvement in the next release...
#
echo -e "**** Checking prerequisite..."
for rpm in ${RPMS_REQUIRED}; do
check_package_is_installed ${rpm}
done
for file in ${TOOLS_REQUIRED}; do
check_file_is_installed ${file}
done
echo -e "**** Checking prerequisite {OK}"
# First Update /etc/services file
echo -e "**** Updating /etc/services file..."
add_service "sgi-cmsd" ${CMSD_PORT} udp "Cluster membership services daemon"
add_service "sgi-crsd" ${CRSD_PORT} udp "Cluster reset services daemon"
add_service "sgi-gcd " ${GCD_PORT} udp "SGI Group membership daemon"
add_service "sgi-cad " ${CAD_PORT} tcp "Cluster Admin daemon"
echo -e "\n/etc/services update OK\n"
# Install RPMS
echo -e "\n**** Installing RPMs...\n"
if [ -n "$1" ]; then
rpms_dir=$1
else
echo -e "Location of the FailSafe binary rpms to be installed:"
echo -e "Default is [${FS_RPMS_DIR}]"
echo -e " Give location or type Enter for default value ?"
read rpms_dir
if [ ! -n "${rpms_dir}" ] ; then
rpms_dir=${FS_RPMS_DIR}
fi
fi
if [ ! -d ${rpms_dir} ]; then
fatal_error "Directory ${rpms_dir} does not exist."
fi
for rpm in ${FS_RPMS_LIST}
do
echo " Installing RPM ${rpm}"
if (rpm -q ${rpm} > /dev/null 2>&1) ; then
echo " (${rpm} already installed ..... skipping ${rpm})"
continue
fi
rpm -ivh --nodeps ${rpms_dir}/${rpm}*
done
echo -e "\nRPMs installation OK\n"
# Check if cluster_admin, cluster_services & failsafe packages are installed
echo -e "\n**** Checking packages installation...\n"
check_package_is_installed cluster_admin
check_package_is_installed cluster_services
check_package_is_installed failsafe
echo -e "\nRPM installation check OK\n"
echo -e "\n**** Updating startup flags...\n"
# Enable fs_cluster application
${FS_BIN_DIR}/fsconfig fs_cluster on
# Disable failsafe application (enabled by cmond)
${FS_BIN_DIR}/fsconfig failsafe off
echo -e "\nStartup flags update OK\n"
# Create symlinks in init level directories to start
# cluster and failsafe at boot time
echo -e "\n**** Creating links in init level directories...\n"
if [ -f ${SUSE_DISTRIB_ID} ]
then
echo "SuSE distribution detected."
level_text=2
level_x=3
elif [ -f ${RH_DISTRIB_ID} ]
then
echo "RedHat distribution detected."
level_text=3
level_x=5
else
echo "Your linux distribution is neither RH nor SuSE"
echo "Give run level for multi-user/text (default 2) ?"
read level_text
if [ -n "${level_text}" ]
then
level_text=2
fi
echo "Give run level for multi-user/X11 (default 3) ?"
read level_x
if [ -n "${level_x}" ]
then
level_x=3
fi
fi
# Create links in init level ${level_text} (Multi-user, text)
create_init_level_symlink fs_cluster ${level_text} S36
create_init_level_symlink fs_cluster ${level_text} K39
create_init_level_symlink failsafe ${level_text} S37
create_init_level_symlink failsafe ${level_text} K37
# Create links in init level ${level_x} (Multi-user, X11)
create_init_level_symlink fs_cluster ${level_x} S36
create_init_level_symlink fs_cluster ${level_x} K39
create_init_level_symlink failsafe ${level_x} S37
create_init_level_symlink failsafe ${level_x} K37
echo -e "\n Links creation OK\n"
echo -e "\n**** Creating an empty database...\n"
/usr/sbin/cdbreinit
echo -e "\n**** FailSafe Installation DONE ****\n"