rc.nodecheck 4.53 KB
Newer Older
1
2
#! /bin/sh
#
Mike Hibler's avatar
Mike Hibler committed
3
# Copyright (c) 2013-2014 University of Utah and the Flux Group.
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
# 
# {{{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
42
# XXX compat with other Emulab rc.* scripts
# We only run on a "boot" invocation, not shutdown/reconfig/reset.
# Note if invoked with no args then treat as "boot"
Mike Hibler's avatar
Mike Hibler committed
43
#
44
45
46
if [ $# -gt 0 -a "$1" != "boot" ]; then
    exit 0
fi
47
48
49
50
51

#
# XXX see if hwinfo returns anything. If not, assume node checks are not
# supported and don't bother with the rest.
#
52
53
# defaults will be collect=0 check=0 

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
if [ "$check" = "0" -a "$collect" = "0" ] ; then
Mike Hibler's avatar
Mike Hibler committed
74
    echo 'testbed says not to run nodecheck, skipping'
75
76
    exit 0
fi
77

Mike Hibler's avatar
Mike Hibler committed
78
79
80
81
82
if [ -d /proc/xen ]; then
    echo "Skipping nodechecks in Xen dom0"
    exit 0
fi

83
84
85
86
87
88
89
90
91
92
93
94
# if asked to collect need the proj directory this project
# (as given by tmcc hwinfo) and mounted to save logs
# Later - try mounting in any case since the static binaries will be better to use if found

collectdir=`echo $testinfo | awk -F \" '{print $2}'`
a=`echo $collectdir | awk -F \/ '{print $2}'`
b=`echo $collectdir | awk -F \/ '{print $3}'`
mountpoint="/$a/$b"

if [ ! -d "$mountpoint" ] ; then
    mkdir -p $mountpoint
fi
95

96
97
98
99
100
mounted=0
isitmounted=$(mount | grep -c $mountpoint)
if [ $isitmounted -eq 0 ] ; then
    mount -o soft,intr,bg fs:$mountpoint $mountpoint
    if [ $? -ne 0 ]; then
Mike Hibler's avatar
Mike Hibler committed
101
	echo "*** Could not mount $mountpoint, nodecheck collect not done"
102
103
104
105
106
	collect=0
    else
	mounted=1
	if [ ! -d "$collectdir" ] ; then
	    mkdir -p $collectdir
107
108
	fi
    fi
109
fi
110

111
112
113
114
if [ -f "/etc/emulab/ismfs" ] ; then
    # MFSes doesn't have all the apps we need, so mount an extra directory
    # and put in the path

115
116
    if [ ! -d $mountpoint/nodecheck/`uname -s`/bin-`uname -m` ] ; then
	echo "Nodecheck - Can not run in MFS mode without having helper programs."
117
	echo "Expecting to have $MFSPROJDIR/nodecheck/`uname -s`/bin-`uname -m` available"
118
119
120
	exit 0
    fi

121
    os=`uname -s`
Dan Reading's avatar
Dan Reading committed
122
    export PATH="/usr/local/sbin:/usr/local/bin:$mountpoint/nodecheck/`uname -s`/bin-`uname -m`:$PATH"
123
    
124
    echo 'Running Hardware Inventory Gather'
125
    bash $BINDIR/checknode $LOGDIR/nodecheck.log
126
127
128
    echo 'Done Running Hardware Inventory'

    if [ $mounted -ne 0 ]; then
129
	umount $mountpoint
130
131
    fi
    exit 0
132
133
134
135
else
    # just don't run if not in a mfs
    :
    exit 0
136
137
fi

Mike Hibler's avatar
Mike Hibler committed
138
139
140
141
142
143
144
145
146
147
148
149
action=""
if [ "$check" = "1" -a "$collect" = "1" ] ; then
    action="collect and check"
else
    if [ "$check" = "1" ] ; then
	action="check"
    else
	action="collect"
    fi
fi

echo "Starting nodecheck $action at `date`"
150
151
152
153

# set path if we have the extra static binaries
os=`uname -s`
if [ -d "$mountpoint"/nodecheck/`uname -s`/bin-`uname -m` ] ; then
Dan Reading's avatar
Dan Reading committed
154
    export PATH="/usr/local/sbin:/usr/local/bin:$mountpoint/nodecheck/`uname -s`/bin-`uname -m`:$PATH"
155
156
157
fi

# if booting node then truncate local log file
158
if [ "$1" = "boot" ] ; then
159
    printf "%s------ Start boottime_nodecheck ------\n" "$(date)" > $LOGDIR/nodecheck.log
160
161
fi

162
bash $BINDIR/checknode $LOGDIR/nodecheck.log
163
164

if [ "$1" = "boot" ] ; then
165
    printf "%s------ Finish boottime_nodecheck -----\n\n" "$(date)" >> $LOGDIR/nodecheck.log
166
167
fi

168
169
170
if [ $mounted -ne 0 ]; then
    umount $mountpoint
fi
171

Mike Hibler's avatar
Mike Hibler committed
172
echo "Finishing nodecheck $action at `date`"
173
exit 0