rc.nodecheck 3.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /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
34
        BINDIR=/usr/local/etc/emulab
35
	LOGDIR=/var/emulab/logs
36
37
fi

38
39
MFSPROJDIR=/proj/emulab-ops

40
41
# defaults will be collect=0 check=0 

42
43
44
45
46
47
48
49
#
# XXX compat with other Emulab rc.* scripts
# We only run on a "boot" invocation, not shutdown/reconfig/reset.
#
if [ $# -gt 0 -a "$1" != "boot" ]; then
    exit 0
fi

50
51
52
53
#
# XXX see if hwinfo returns anything. If not, assume node checks are not
# supported and don't bother with the rest.
#
54
testinfo=`$BINDIR/tmcc hwinfo | grep TESTINFO`
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
if [ -z "$testinfo" ]; then
    echo "Skipping nodechecks tmcc does not support hwinfo"
    exit 0
fi

x=`echo $testinfo | awk -F = '{print $3}' | awk '{print $1}'`
if [ -n "$x" ] ; then
    collect=$x
else
    collect=0
fi
x=`echo $testinfo | awk -F = '{print $4}'`
if [ -n "$x" ] ; then
    check=$x
else
    check=0
fi

73
    
74

Mike Hibler's avatar
Mike Hibler committed
75
if [ -f "/etc/emulab/ismfs" ] ; then
76
77
    if [ "$collect" = "0" ] ; then
	echo 'testbed says not run nodecheck collect, skipping'
78
79
	exit 0
    fi
80

81
82
    # MFSes don't have all the apps we need, so mount an extra directory
    # and put in the path
83
84
85
86
87
88
89
90
91
    collectdir=`echo $testinfo | awk -F \" '{print $2}'` # make sure we are in the emulab-ops pid
    a=`echo $collectdir | awk -F \/ '{print $2}'`
    b=`echo $collectdir | awk -F \/ '{print $3}'`
    mountpoint="/$a/$b"
    if [ "$mountpoint" != "$MFSPROJDIR" ] ; then
	echo "Nodecheck - Can not run in MFS mode without being in emulab-ops pid."
	exit 0
    fi

92
93
    if [ ! -d "$MFSPROJDIR" ] ; then
	mkdir -p $MFSPROJDIR
94
95
    fi
    mounted=0
96
97
    if [ ! -d "$MFSPROJDIR/nodecheck" ] ; then
	mount -o soft,intr,bg fs:$MFSPROJDIR $MFSPROJDIR
98
	if [ $? -ne 0 ]; then
99
	    echo '*** Could not mount $MFSPROJDIR, nodecheck gather not done'
100
101
102
103
104
	    exit 0
	fi
	mounted=1
    fi
    os=`uname -s`
105
106
    if [ ! -f $MFSPROJDIR/nodecheck/$os/bin/bash ] ; then
	echo "*** Did not find expected bash in $MFSPROJDIR/$os/bin"
107
108
    fi

109
    export PATH="/usr/local/bin:$MFSPROJDIR/nodecheck/$os/bin:$PATH"
110
111

    echo 'Running Hardware Inventory Gather'
112
    bash $BINDIR/checknode $@
113
114
115
    echo 'Done Running Hardware Inventory'

    if [ $mounted -ne 0 ]; then
116
	umount $MFSPROJDIR
117
118
119
120
    fi
    exit 0
fi

121
if [ "$check" = "0" -a "$collect" = "0" ] ; then
122
123
124
125
    echo 'testbed says not run nodecheck, skipping'
    exit 0
fi

126
127
128
echo "Running nodechecks"
# truncate file at boot time
if [ "$1" = "boot" ] ; then
129
    printf "%s------ Start boottime_nodecheck ------\n" "$(date)" > $LOGDIR/nodecheck.log
130
131
fi

132
bash $BINDIR/checknode $LOGDIR/nodecheck.log
133
134

if [ "$1" = "boot" ] ; then
135
    printf "%s------ Finish boottime_nodecheck -----\n\n" "$(date)" >> $LOGDIR/nodecheck.log
136
137
138
139
140
fi

echo "Done with nodechecks"

exit 0