Horms wrote:
> For what it is worth I agree with Joe. I like the idea of a simple wrapper
> that looks for/at /proc/net/ip_vs and exec the appropriate version of
> ipvsadm.
below is my script for doing this. At the bottom you add the files
you are interested in tracking, in my case /usr/src/linux, /usr/src/ipvs,
/sbin/ipvsadm etc
Say we're booted onto a machine with 2.2.19 and ipvs-1.0.7
The script
1. deletes that file IF it is a link.
2. looks for files in this order
foo-1.0.7-2.2.19
foo-2.2.19-1.0.7
foo-1.0.7
foo-2.2.19
The first one it finds is linked to foo
Here is the directory listings after the script has been run
/sbin/ipvsadm*
-rw-r--r-- 1 root root 566 Mar 18 15:01
/sbin/ipvsadm-restore-2.4.3
-rw-r--r-- 1 root root 797 Mar 22 12:57 /sbin/ipvsadm-save-2.4.3
-rwxr-xr-x 1 root root 66786 Apr 18 15:31 /sbin/ipvsadm-2.4.3*
-rw-r--r-- 1 root root 797 Mar 27 09:25 /sbin/ipvsadm-save-1.0.7
-rw-r--r-- 1 root root 566 Mar 27 09:25
/sbin/ipvsadm-restore-1.0.7
-rwxr-xr-x 1 root root 70456 Apr 27 12:05 /sbin/ipvsadm-1.0.7*
lrwxrwxrwx 1 root root 18 Apr 27 12:43 /sbin/ipvsadm-save ->
ipvsadm-save-1.0.7
lrwxrwxrwx 1 root root 21 Apr 27 12:43 /sbin/ipvsadm-restore ->
ipvsadm-restore-1.0.7
lrwxrwxrwx 1 root root 13 Apr 27 12:43 /sbin/ipvsadm ->
ipvsadm-1.0.7*
/usr/src
drwxr-xr-x 5 root root 1024 Apr 20 14:59 ipvs-0.2.11/
drwxr-xr-x 14 root root 2048 Apr 25 14:50 linux-0.2.11-2.4.3-SMP/
lrwxrwxrwx 1 root root 29 Apr 27 10:01 linux-0.2.11-2.4.3 ->
linux-0.2.11-2.4.3-monolithic/
drwxr-xr-x 14 root root 2048 Apr 27 11:38
linux-0.2.11-2.4.3-monolithic/
drwxr-xr-x 5 root root 1024 Apr 19 15:37 ipvs-1.0.7-2.2.19/
drwxr-xr-x 15 root root 2048 Apr 27 11:56 linux-1.0.7-2.2.19/
lrwxrwxrwx 1 root root 18 Apr 27 12:45 linux ->
linux-1.0.7-2.2.19/
lrwxrwxrwx 1 root root 17 Apr 27 12:45 ipvs ->
ipvs-1.0.7-2.2.19/
-----
Here's the script
#always have the right System.map (in /usr/src/linux), ipvsadm...
#no matter which kernel version you're running
#Joseph Mack (C) 2001 released under GPL, jmack@xxxxxxxx,
#To use:
#for files/directories which are kernel version specific.
#
#eg you'll get error messages about System.map being the wrong version unless
#you have /usr/src/linux linked to the same version of linux as you booted from.
#eg in /sbin: ipvsadm-2.4.1, ipvsadm-2.2.18 which is called as /sbin/ipvsadm
#
#in main you send a list of directories/files like /usr/src/linux/,
/sbin/ipvsadm
#for each item in this list, this program will
#a. delete /usr/src/linux if linux is a link, otherwise do nothing if linux is
a file
#b. look for linux-x.x.x where x.x.x is the kernel version
#c. ln -s linux-x.x.x linux, else issue notice if there is no linux-x.x.x
#
#---------------------
ip_vs(){
#IPVS_VERSION is assigned the version number of IPVS currently loaded
if [ "$LINUX_KERNEL_SERIES" = "2.2" ]
then
IPVS_VERSION=`grep "IP Virtual Server version" /proc/net/ip_masq/vs |
awk '{print \$5}'`
echo $IPVS_VERSION
elif [ "$LINUX_KERNEL_SERIES" = "2.4" ]
then
IPVS_VERSION=`grep "IP Virtual Server version" /proc/net/ip_vs | awk
'{print \$5}'`
echo $IPVS_VERSION
else
echo "Error: kernel $UNAME_R not from 2.2 or 2.4 series"
exit -1
fi
}
make_link(){
BASENAME=`/usr/bin/basename $1`
#echo "BASENAME $BASENAME"
cd `/usr/bin/dirname $1`
#if $BASENAME a link or doesn't exist
if [ -L $BASENAME -o ! \( -e $BASENAME \) ]
then
#only do something if we have a target
if [ -d $BASENAME-${UNAME_R}-${IPVS_VERSION} -o -f
$BASENAME-${UNAME_R}-${IPVS_VERSION} ]
then
if [ -L $BASENAME ] #if the filename is a link, delete it
then
/bin/rm $BASENAME
fi
#there is no $BASENAME now.
/bin/ln -s $BASENAME-${UNAME_R}-${IPVS_VERSION} $BASENAME
elif [ -d $BASENAME-${IPVS_VERSION}-${UNAME_R} -o -f
$BASENAME-${IPVS_VERSION}-${UNAME_R} ]
then
if [ -L $BASENAME ] #if the filename is a link, delete it
then
/bin/rm $BASENAME
fi
#there is no $BASENAME now.
/bin/ln -s $BASENAME-${IPVS_VERSION}-${UNAME_R} $BASENAME
elif [ -d $BASENAME-${IPVS_VERSION} -o -f $BASENAME-${IPVS_VERSION} ]
then
if [ -L $BASENAME ] #if the filename is a link, delete it
then
/bin/rm $BASENAME
fi
#there is no $BASENAME now.
/bin/ln -s $BASENAME-${IPVS_VERSION} $BASENAME
elif [ -d $BASENAME-${UNAME_R} -o -f $BASENAME-${UNAME_R} ]
then
if [ -L $BASENAME ] #if the filename is a link, delete it
then
/bin/rm $BASENAME
fi
#there is no $BASENAME now.
/bin/ln -s $BASENAME-${UNAME_R} $BASENAME
else
echo "no $BASENAME-${UNAME_R} or $BASENAME-${IPVS_VERSION} to
link to"
fi
else
echo "cannot delete $BASENAME, doesn't exist or is a regular file"
fi
cd -
}
#-----------------
#main:
echo "rc.system_map "
UNAME_R=`/bin/uname -r`
LINUX_KERNEL_SERIES=${UNAME_R%.*}
ip_vs
if [ $? != "0" ]
then
echo "Error: unable to determine IPVS version"
exit -1
fi
make_link /usr/src/linux
make_link /sbin/ipvsadm
make_link /sbin/ipvsadm-save
make_link /sbin/ipvsadm-restore
make_link /usr/src/ipvs
#make_link /bin/foo #a test, foo-x.x.x doesn't exist
#-----------------
--
Joseph Mack PhD, Senior Systems Engineer, Lockheed Martin
contractor to the National Environmental Supercomputer Center,
mailto:mack.joseph@xxxxxxx ph# 919-541-0007, RTP, NC, USA
|