Commit 6de18726 authored by Mike Hibler's avatar Mike Hibler
Browse files

Mike's first pass; minor changes.

Merge rc.config changes into the real script.
Reduce rc.nodecheck varients to a single shell script and get rid of rc subdir.
Add copyrights.
Add GNUmakefile install target (but not used yet).
Replace some hardwired paths with vars from paths.sh.
parent d94f1e05
......@@ -83,6 +83,17 @@ path-install: dir-install
$(INSTALL) -m 755 $(SRCDIR)/paths.pm $(ETCDIR)/paths.pm
$(INSTALL) -m 755 $(SRCDIR)/paths.sh $(ETCDIR)/paths.sh
nodecheck-install: dir-install
$(INSTALL) -m 644 $(SRCDIR)/checknode/checkutils.sh $(BINDIR)/checkutils.sh
$(INSTALL) -m 644 $(SRCDIR)/checknode/hbis.sh $(BINDIR)/hbis.sh
$(INSTALL) -m 755 $(SRCDIR)/checknode/cpucheck $(BINDIR)/cpucheck
$(INSTALL) -m 755 $(SRCDIR)/checknode/diskcheck $(BINDIR)/diskcheck
$(INSTALL) -m 755 $(SRCDIR)/checknode/memcheck $(BINDIR)/memcheck
$(INSTALL) -m 755 $(SRCDIR)/checknode/niccheck $(BINDIR)/niccheck
$(INSTALL) -m 755 $(SRCDIR)/checknode/gatherenv $(BINDIR)/gatherenv
$(INSTALL) -m 755 $(SRCDIR)/checknode/rc.nodecheck $(BINDIR)/rc/rc.checknode
common-script-install: dir-install
$(INSTALL) -m 755 $(SRCDIR)/libsetup.pm $(BINDIR)/libsetup.pm
$(INSTALL) -m 755 $(SRCDIR)/libtmcc.pm $(BINDIR)/libtmcc.pm
......
#
# Copyright (c) 2013 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
#function debugging by setting FUNCDEBUG=y
#exit on unbound var
......
#!/bin/bash
#
# Copyright (c) 2013 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
echo -n ' Cpucheck..'
......
#! /bin/bash
#
# Copyright (c) 2013 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
echo -n ' Starting diskcheck..'
......
#! /bin/bash
#
# Copyright (c) 2013 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
mywhich() {
mypath=$(env | grep PATH)
......@@ -13,17 +35,27 @@ mywhich() {
return 1
}
if [ -z "$BINDIR" ] ; then
if [ -r /etc/emulab/paths.sh ] ; then
source /etc/emulab/paths.sh
else
BINDIR=/usr/local/etc/emulab
LOGDIR=/var/tmp
fi
fi
PROJDIR=/proj/emulab-ops
# 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 `mywhich bash`)
if [ -z "$verbash" ] ; then
verbash=$(file -m /proj/emulab-ops/nodecheck/FreeBSD/bin/magic `mywhich bash`)
verbash=$(file -m $PROJDIR/nodecheck/FreeBSD/bin/magic `mywhich bash`)
fi
if [ "$verbash" != "${verbash/busybox}" ] ; then
# NO! we are not, retstart using the correct bash
# we not be in a loop since correct path is now set
export PATH=/proj/emulab-ops/nodecheck/$(uname -s)/bin:$PATH
export PATH=$PROJDIR/nodecheck/$(uname -s)/bin:$PATH
bash $0
exit 0
fi
......@@ -38,7 +70,7 @@ gatherinv_main() {
checks="disk cpu mem nic"
for i in $checks ; do
bash /usr/local/etc/emulab/${i}check /var/emulab/logs/nodecheck.log /tmp/nodecheck.log.tb
bash $BINDIR/${i}check $LOGDIR/nodecheck.log /tmp/nodecheck.log.tb
done
set +e
......@@ -53,38 +85,38 @@ set +e
{ printhwinv
} > /tmp/nodecheck.log.inv
host=$(/usr/local/etc/emulab/tmcc.bin nodeid)
host=$($BINDIR/tmcc.bin nodeid)
# make sure proj got mounted
if [ ! -d /proj/emulab-ops ] ; then
if [ ! -d $PROJDIR ] ; then
echo "OHhh all this work for nothing"
echo "/proj/emulab-ops not mounted can't save info"
echo "$PROJDIR not mounted can't save info"
exit 1
fi
# have needed dirs ?
if [ ! -d /proj/emulab-ops/nodecheck/FullInventory ] ; then
mkdir -p /proj/emulab-ops/nodecheck/FullInventory
chmod 755 /proj/emulab-ops/nodecheck /proj/emulab-ops/nodecheck/FullInventory
if [ ! -d $PROJDIR/nodecheck/FullInventory ] ; then
mkdir -p $PROJDIR/nodecheck/FullInventory
chmod 755 $PROJDIR/nodecheck $PROJDIR/nodecheck/FullInventory
fi
$(cp /tmp/nodecheck.log.tb.new /proj/emulab-ops/nodecheck/$host);
$(cp /tmp/nodecheck.log.inv /proj/emulab-ops/nodecheck/FullInventory/$host);
$(chmod g+rw /proj/emulab-ops/nodecheck/$host /proj/emulab-ops/nodecheck/FullInventory/$host);
$(cp /tmp/nodecheck.log.tb.new $PROJDIR/nodecheck/$host);
$(cp /tmp/nodecheck.log.inv $PROJDIR/nodecheck/FullInventory/$host);
$(chmod g+rw $PROJDIR/nodecheck/$host $PROJDIR/nodecheck/FullInventory/$host);
# Test what found local against what is in the database
readtmcinfo # info from tmcc.bin hwinv
# for testing readtmcinfo /proj/emulab-ops/nodecheck/test
# for testing readtmcinfo $PROJDIR/nodecheck/test
copytmcinfo # copy into hwinvcopy
readtmcinfo /tmp/nodecheck.log.tb.new # read local found into hwinv
comparetmcinfo /tmp/nodecheck.diff # file for output
if [ -s /tmp/nodecheck.diff ] ; then
cat /tmp/nodecheck.diff
$(cp /tmp/nodecheck.diff /proj/emulab-ops/nodecheck/${host}.diff)
$(chmod g+rw /proj/emulab-ops/nodecheck/${host}.diff);
$(cp /tmp/nodecheck.diff $PROJDIR/nodecheck/${host}.diff)
$(chmod g+rw $PROJDIR/nodecheck/${host}.diff);
else
# no diff maybe it got better
rm -f /proj/emulab-ops/nodecheck/${host}.diff
rm -f $PROJDIR/nodecheck/${host}.diff
fi
# echo "NEED TO ENABLE rm -f /tmp/nodecheck.log.tb /tmp/nodecheck.log.inv"
......
#
# Copyright (c) 2013 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
# what a mess, need to replace with something sane
......
#!/bin/bash
#
# Copyright (c) 2013 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
_1KiB=1
_1KMiB=1024
......
#!/bin/bash
#
# Copyright (c) 2013 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
echo -n ' Starting niccheck.. '
......
#! /bin/sh
#
# Copyright (c) 2013 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
#
# This is a shell script instead of a perl script since we want to use this
# in the FreeBSD-based frisbee MFS which does not include perl. It also uses
# only "basic" sh syntax, where the other shell scripts require bash.
#
if [ -r /etc/emulab/paths.sh ]; then
. /etc/emulab/paths.sh
else
BINDIR=/etc/testbed
fi
PROJDIR=/proj/emulab-ops
mode="check"
checks="disk cpu mem time nic"
if [ $# -gt 1 -a "$2" = "gather" ]; then
mode="gather"
# do not run timecheck for MFS hw gather mode
checks="disk cpu mem nic gather"
fi
host=`$BINDIR/tmcc.bin nodeid`
# XXX MFSes don't have all the apps we need, so mount an extra directory
if [ -f "$ETCDIR/ismfs" ] ; then
# XXX only support gather in the MFS
if [ $mode != "gather" ]; then
echo '*** nodecheck skipped in MFS'
exit 0
fi
if [ ! -d "$PROJDIR" ] ; then
mkdir $PROJDIR
fi
mounted=0
if [ ! -d "$PROJDIR/nodecheck" ] ; then
mount -o soft,intr,bg fs:$PROJDIR $PROJDIR
if [ $? -ne 0 ]; then
echo '*** Could not mount $PROJDIR, nodecheck not done'
exit 0
fi
mounted=1
fi
os=`uname -s`
export PATH="/usr/local/bin:$PROJDIR/nodecheck/$os/bin:$PATH"
echo 'Running Hardware Inventory Gather'
bash $BINDIR/gatherinv
echo 'Done Running Hardware Inventory'
if [ $mounted -ne 0 ]; then
umount $PROJDIR
fi
exit 0
fi
#
# XXX see if hwinfo returns anything. If not, assume node checks are not
# supported and don't bother with the rest.
#
hwinfo=`$BINDIR/tmcc hwinfo`
if [ -z "$hwinfo" ]; then
echo "Skipping nodechecks"
exit 0
fi
echo "Running nodechecks"
# truncate file at boot time
if [ "$1" = "boot" ] ; then
echo "-- Start boot_time_node_check --" > $LOGDIR/nodecheck.log
cp /dev/null /tmp/nodecheck.log.tb
for i in $checks
do
bash $BINDIR/${i}check $LOGDIR/nodecheck.log /tmp/nodecheck.log.tb
done
echo "-- Finish boot_time_node_check --" >> $LOGDIR/nodecheck.log
if [ -f /tmp/nodecheck.log.tb ] ; then
cp /tmp/nodecheck.log.tb $PROJDIR/nodecheck/$host
cp /tmp/nodecheck.log.inv $PROJDIR/nodecheck/$host.full
chmod a+r $PROJDIR/nodecheck/$host*
fi
else
rm -f /tmp/nodecheck.log.tb
for i in $checks
do
bash $BINDIR/${i}check $LOGDIR/nodecheck.log
done
fi
echo "Done with nodechecks"
exit 0
#!/usr/bin/perl -w
#
# Copyright (c) 2004-2012 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
use English;
use Getopt::Std;
#
# This is the entrypoint to running the config scripts. It would be nice
# to just stick these in a directory and run them all, but order matters
# and I hate naming things so that the order comes up the way I want it!
# Anyway, this script fires off the rc scripts in the proper order.
#
# All of the scripts accept a -j argument since in some cases we run these
# on behalf of a vnode, and the script needs to tell the tmcc library the
# vnodeid for when it talks to tmcd. Otherwise, libtmcc knows when it is
# running *inside* a vnode and sets things up properly for talking to tmcd.
#
sub usage()
{
print "Usage: " .
scriptname() . " [-j vnodeid] boot|shutdown|reconfig|reset\n";
exit(1);
}
my $optlist = "j:dM";
my %options = ();
my $action = "boot";
my $debug = 0;
my $vnodeid;
my $updatemasterpasswdfiles = 0;
# Turn off line buffering on output
$| = 1;
# Drag in path stuff so we can find emulab stuff.
BEGIN { require "/etc/emulab/paths.pm"; import emulabpaths; }
# Only root.
if ($EUID != 0) {
die("*** $0:\n".
" Must be root to run this script!\n");
}
#
# Load the OS independent support library. It will load the OS dependent
# library and initialize itself.
#
use libsetup;
use libtmcc;
use librc;
# Protos.
sub doboot();
sub doshutdown();
sub doreconfig();
sub docleanup();
# Parse command line.
if (! getopts($optlist, \%options)) {
usage();
}
if (defined($options{'j'})) {
$vnodeid = $options{'j'};
libsetup_setvnodeid($vnodeid);
}
if (defined($options{'d'})) {
$debug++;
}
if (defined($options{'M'})) {
$updatemasterpasswdfiles = 1;
}
# Allow default above.
if (@ARGV) {
$action = $ARGV[0];
}
#
# The master list of scripts. Add in the right order! To speed things up
# specify a shorter set for the MFS.
#
my @bootscripts;
my %bootscript_args = ( 'rc.accounts' => $updatemasterpasswdfiles ?
'-M' : '' );
if (MFS()) {
@bootscripts = ("rc.misc", "rc.localize", "rc.mounts", "rc.accounts",
"rc.hostnames", "rc.keys", "rc.tarfiles", "rc.rpms",
"rc.tpmsetup");
}
elsif (FAKEJAILED()) {
@bootscripts = ("rc.misc", "rc.keys", "rc.route", "rc.tunnels",
"rc.ifconfig", "rc.progagent");
}
elsif (WINDOWS()) {
@bootscripts = ("rc.misc", "rc.localize", "rc.keys", "rc.mounts",
"rc.accounts", "rc.topomap",
"rc.route", "rc.ifconfig",
"rc.hostnames", "rc.lmhosts", "rc.syncserver",
# rc.progagent is run by a separate service named ProgAgent.
# It's started by EmulabStartup after rc.bootsetup runs.
"rc.tarfiles", "rc.rpms");
}
else {
@bootscripts = ("rc.firewall", "rc.tpmsetup",
"rc.misc", "rc.localize", "rc.keys", "rc.mounts",
"rc.blobs",
"rc.topomap", "rc.accounts",
"rc.route", "rc.tunnels", "rc.ifconfig", "rc.delays",
"rc.hostnames", "rc.trace",
"rc.syncserver", "rc.trafgen",
"rc.tarfiles", "rc.rpms", "rc.progagent", "rc.linkagent",
"rc.tiptunnels", "rc.motelog", "rc.simulator", "rc.diskagent",
"rc.nodecheck"
);
}
# Execute the action.
SWITCH: for ($action) {
/^boot$/i && do {
doboot();
last SWITCH;
};
/^shutdown$/i && do {
doshutdown();
last SWITCH;
};
/^reconfig$/i && do {
doreconfig();
last SWITCH;
};
/^reset$/i && do {
docleanup();
last SWITCH;
};
fatal("Invalid action: $action");
}
exit(0);
sub doaction($@)
{
my ($what, @scripts) = @_;
#
# Run all the scripts. We run them all, not worrying about individual
# failure. Right thing to do? Maybe stop on failure?
#
my $optarg = (defined($vnodeid) ? "-j $vnodeid" : "");
#
# Grab our manifest so we can enable/disable/replace this script and
# run (or not) its hooks.
#
my %manifest = ();
getmanifest(\%manifest);
foreach my $script (@scripts) {
my $bargs = '';
if (exists($bootscript_args{$script})
&& defined($bootscript_args{$script})) {
$bargs = $bootscript_args{$script};
}
# No need to install all this cruft on the MFS or other small envs.
next
if (!-x "$BINDIR/rc/$script");
runbootscript(\%manifest,"$BINDIR/rc",$script,$what,"$optarg $bargs $what");
}
}
#
# Boot Action.
#
sub doboot()
{
doaction("boot", @bootscripts);
}
#
# Shutdown Action.
#
sub doshutdown()