Commit ef62ec20 authored by Dan Reading's avatar Dan Reading
Browse files

Rework gathering inventory. Only do gather fuctions not full checks. Getting...

Rework gathering inventory. Only do gather fuctions not full checks. Getting read/write speed on Linux now works with addition of staticely built dd.
parent ab508f0c
#function debugging by setting FUNCDEBUG=y
# add static binaries if needed
declare mfsmode="" #are we running in a MFS (ie busybox) mode
if [ -f /etc/emulab/ismfs ] ; then
meos=$(uname -s)
mfsmode=1
mfs_base="/proj/emulab-ops/nodecheck"
mfs_osdir="${mfs_base}/${meos}"
mfs_bin="${mfs_osdir}/bin"
mfs_lib="${mfs_osdir}/lib"
if [ $PATH == ${PATH/${mfs_bin}} ] ; then
if [ -d ${mfs_osdir} ] ; then
export PATH=/proj/emulab-ops/nodecheck/${meos}/bin:$PATH
fi
fi
else
mfsmode=0
fi
#exit on unbound var
set -u
#exit on any error
set -e
declare errext_val
# Gobal Vars
declare NOSM="echo" #do nothing command
declare host #emulab hostname
declare failed="" #major falure to be commicated to user
declare os="" #[Linux|FreeBSD] for now
declare mfsmode="" #are we running in a MFS (ie busybox) mode
declare -a todo_exit
declare -A hwinv # hwinv from tmcc.bin
#declare -A tcm_out # hwinv for output
#declare -A tcm_inv # what we have discovered
# one arg 'on' or anything else
setmfsmode() {
[[ "$1" == "on" ]] && mfsmode="on" || mfsmode=""
# any command causes exit if -e option set
# including a grep just used so see if some sting is in a file
save_e() {
x=$-
[[ "${x/e}" == "${x}" ]] && errexit_val=off || errexit_val=on
}
restore_e() {
[[ $errexit_val == "on" ]] && set -e || set +e
}
# give some indication of exit on ERR trap
err_report() {
echo "TRAP ERR at $1"
}
trap 'err_report $FUNCNAME:$LINENO' ERR
# read info from tmcc no args uses the globel array hwinv
# if $1 then use that for a input file else use tmcc.bin
......@@ -174,6 +203,24 @@ findSmartctl() {
return 0
}
function on_exit()
{
for i in "${todo_exit[@]}" ; do
echo "EXIT TODO: $i"
$($i)
done
}
function add_on_exit()
{
local n=${#todo_exit[*]}
todo_exit[$n]="$@"
if [[ $n -eq 0 ]]; then
trap on_exit EXIT
fi
}
# setup logging
initlogs () {
funcdebug $FUNCNAME:$LINENO enter $@
......@@ -185,9 +232,12 @@ initlogs () {
touch ${logfile4tb}
# end XXX XXX
tmplog=/tmp/.$$.log ; cat /dev/null > ${tmplog} # create and truncate
add_on_exit "rm -f $tmplog"
logout=/tmp/.$$logout.log ; touch ${logout} # make it exist
add_on_exit "rm -f $logout"
tmpout=/tmp/.$$tmpout.log ; touch ${tmpout}
add_on_exit "rm -f $tmpout"
# tmpfunctionout=/tmp/.$$tmpfunctionout.log
funcdebug $FUNCNAME:$LINENO leave
......@@ -325,4 +375,4 @@ printf "PROGRAMMING ERROR $FUNCNAME $LINENO \n" && exit 1
# <<EOF
#
#EOF
#}
\ No newline at end of file
#}
......@@ -516,7 +516,7 @@ getsectors() {
fi
# fake and go by the size
res=${res%%MB*}
res=${res#* }
res=${res##* }
echo $(( $res * 2048 )) # assume 512 byte sectors
return 0
fi
......@@ -548,7 +548,12 @@ getwspeed() {
canwe=$(df | grep $hdname)
[[ $canwe ]] && { echo mounted; return 0; }
if [ "$os" == "Linux" ] ; then
args="bs=64k iflag=direct count=8000"
if [ "$mfsmode" == "1" ] ; then
# static dd we are using may now match kernel call for direct i/o, guess
args="bs=64k count=8000"
else
args="bs=64k iflag=direct count=8000"
fi
elif [ "$os" == "FreeBSD" ] ; then
args="bs=64k count=8000"
fi
......@@ -559,6 +564,7 @@ getwspeed() {
{
$(dd if=/dev/zero of=$hdname $args)
} > /tmp/ddresultw 2>&1
add_on_exit "rm -f /tmp/ddresultw"
res=$(grep bytes /tmp/ddresultw)
echo $(parsedd $res)
return 0
......@@ -577,6 +583,7 @@ getrspeed() {
{
$(dd of=/dev/null if=$hdname $args)
} > /tmp/ddresultr 2>&1
add_on_exit "rm -f /tmp/ddresultr"
res=$(grep bytes /tmp/ddresultr)
echo $(parsedd $res)
return 0
......@@ -584,7 +591,12 @@ getrspeed() {
parsedd() {
if [ "$os" == "Linux" ] ; then
echo $8
y=$9
if [ $y != ${y/MB} ] ; then
x=$8
else
x="PareddError"
fi
elif [ "$os" == "FreeBSD" ] ; then
x=$7
x=${x#(}
......
#! /bin/bash
echo -n ' Gathering Inventory..'
# need to make sure we are running with a full verseion of bash
if [ -f '/etc/emulab/ismfs' ] ; then
# check to see if we are using correct bash
verbash=$(file `which bash`)
if [ "$verbash" != "${verbash/busybox}" ] ; then
# NO! we do not, retstart using new bash
# we not be in a loop since correct path is now set
export PATH=/proj/emulab-ops/nodecheck/$(uname -s)/bin:$PATH
bash $0
exit 0
fi
fi
source checkutils.sh
gatherinv_main() {
echo -n ' Gathering Inventory..'
$(cp /dev/null /tmp/nodecheck.log.tb)
checks="disk cpu mem nic"
set +e
for i in $checks ; do
bash /usr/local/etc/emulab/${i}check /var/emulab/logs/nodecheck.log /tmp/nodecheck.log.tb
done
# cat /tmp/nodecheck.log.tb
readtmcinfo /tmp/nodecheck.log.tb
readtmcinfo /tmp/nodecheck.log.tb
mv /tmp/nodecheck.log.tb /tmp/nodecheck.bk
#mv /tmp/nodecheck.log.tb /tmp/nodecheck.bk
{ printtmcinfo
{ printtmcinfo
} > /tmp/nodecheck.log.tb
{ printhwinv
{ printhwinv
} > /tmp/nodecheck.log.inv
host=$(tmcc.bin nodeid)
$(cp /tmp/nodecheck.log.tb /proj/emulab-ops/nodecheck/$host);
$(cp /tmp/nodecheck.log.inv /proj/emulab-ops/nodecheck/$host.full);
$(chmod a+r /proj/emulab-ops/nodecheck/$host*);
echo "NEED TO ENABLE rm -f /tmp/nodecheck.log.tb /tmp/nodecheck.log.inv"
}
gatherinv_main $0
......
......@@ -35,24 +35,37 @@ BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
#@checkscripts = ("disk", "cpu", "mem", "time", "nic", "diskspeed");
# do not run timecheck for MFS hw gather mode
#@checkscripts = ("disk", "cpu", "mem", "time", "nic");
@checkscripts = ("disk", "cpu", "mem", "nic", "gather");
@checkscripts = ("disk", "cpu", "mem", "time", "nic");
$host = `/usr/bin/tmcc.bin nodid`;
#$host = `hostname`;
#if ( -r '/var/emulab/boot/realname' ) {
# $host = `cat /var/emulab/boot/realname`;
#} elsif ( -f '/var/emulab/boot/nodeid' ) {
# $host = `cat /var/emulab/boot/nodeid`;
#}
system("echo 'Running nodechecks'");
$host = `hostname`;
if ( -r '/var/emulab/boot/realname' ) {
$host = `cat /var/emulab/boot/realname`;
} elsif ( -f '/var/emulab/boot/nodeid' ) {
$host = `cat /var/emulab/boot/nodeid`;
}
chomp($host);
my $os = `uname -s`;
chomp($os);
if ($os eq "Linux") {
$ENV{'PATH'} = "/usr/local/bin:/proj/emulab-ops/nodecheck/bin_linux:$ENV{'PATH'}";
}
if ( -r '/etc/emulab/ismfs' ) {
system("mount fs.emulab.net:/q/proj/emulab-ops /proj/emulab-ops");
my $os = `uname -s`;
chomp($os);
if ($os eq "Linux") {
$ENV{'PATH'} = "/usr/local/bin:/proj/emulab-ops/nodecheck/Linux/bin:$ENV{'PATH'}";
}
if ($os eq "FreeBSD") {
$ENV{'PATH'} = "/usr/local/bin:/proj/emulab-ops/nodecheck/FreeBSD/bin:$ENV{'PATH'}";
}
system("echo 'Running Hardware Inventory Gather'");
system("bash /usr/local/etc/emulab/gatherinv");
system("echo 'Done Running Hardware Inventory'");
exit (0);
}
system("echo 'Running nodechecks'");
if (!$ARGV[0]) {
$action = "noboot";
......@@ -63,22 +76,15 @@ if (!$ARGV[0]) {
# truncate file at boot time
if ($action eq "boot") {
system("echo 'Start boot_time_node_check' > /var/emulab/logs/nodecheck.log");
system("cp /dev/null /tmp/nodecheck.log.tb");
foreach my $i (@checkscripts) {
system("bash /usr/local/etc/emulab/${i}check /var/emulab/logs/nodecheck.log");
}
system("echo '-- Start boot_time_node_check --' > /var/emulab/logs/nodecheck.log");
}
foreach my $i (@checkscripts) {
system("bash /usr/local/etc/emulab/${i}check /var/emulab/logs/nodecheck.log");
}
if ($action eq "boot") {
system("echo '-- Finish boot_time_node_check --' >> /var/emulab/logs/nodecheck.log");
if ( -e "/tmp/nodecheck.log.tb" ) {
system("cp /tmp/nodecheck.log.tb /proj/emulab-ops/nodecheck/$host");
system("cp /tmp/nodecheck.log.inv /proj/emulab-ops/nodecheck/$host.full");
system("chmod a+r /proj/emulab-ops/nodecheck/$host*");
}
} else {
system("rm -f /tmp/nodecheck.log.tb");
foreach my $i (@checkscripts) {
system("bash /usr/local/etc/emulab/${i}check /var/emulab/logs/nodecheck.log");
}
}
system("echo 'Done with nodechecks'");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment