checknode 6.45 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
#! /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/>.
# 
# }}}
#

Dan Reading's avatar
Dan Reading committed
25
# checknode now has two duties. gather/collect in MFS mode
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# and run in normal mode so sub-programs can be called by sourcing,
# letting everthing run in the same shell. Sub-programs should 
# also be allowed to run standalone.

source checkutils.sh
set -u
set -e

nodecheck_main() {
    (( $check_flag )) && checks="time cpu mem nic disk" || checks="cpu mem nic disk"
    for i in $checks ; do
	source $BINDIR/${i}check $LOGDIR/nodecheck.log 
    done
    return 0
}


gatherinv_main() {

    echo -n '  Gathering Inventory..'
    (( ! $collect_flag )) && echo "Hmmm tmcc says not to collect. Doing so anyway."
    
    checks="disk cpu mem nic"
    for i in $checks ; do
	source $BINDIR/${i}check $LOGDIR/nodecheck.log 
    done
    return 0
}

postprocessing()
{
    timestamp=$(date +%y%m%d%H%M%S)

    if (( $collect_flag )) ; then

        # read in the newly found info into hwinv array
	readtmcinfo /tmp/nodecheck.log.tb hwinv

        # print it back out in tmcc hwinfo format
	{ printtmcinfo
} > /tmp/nodecheck.log.tb.new # .new not necessary should reuse old name
        # note what kernel we are running
	printf "# KERNEL %s\n" "$(uname -svrm)" >> /tmp/nodecheck.log.tb.new
	# add which mode we running as
	printf "# ismfs=%s %s\n" "$mfsmode" "$(getfromtb TESTINFO)" >> /tmp/nodecheck.log.tb.new

    # print the full listng of found inventory
	{ printhwinv
} > /tmp/nodecheck.log.inv
	printf "# KERNEL %s\n" "$(uname -svrm)" >> /tmp/nodecheck.log.inv
	# add which mode we running as
	printf "# ismfs=%s %s\n"  "$mfsmode" "$(getfromtb TESTINFO)" >> /tmp/nodecheck.log.inv

    # make sure projdir is available
        if [ ! -d ${projdir} ] ; then
            dirn="${projdir%${projdir##*/}}"
            [[ "${dirn:=./}" != "/" ]] && dirn="${dirn%?}"
	    dirnmounted=$(df | grep $dirn)
	    if [ -n "$dirnmounted" ] ; then
    		if [ ! -d ${projdir} ] ; then
		    mkdir ${projdir}
    		    if [ ! -d ${projdir} ] ; then
			echo "Was not able to make $projdir...whats up with that"
			exit 1
		    else
			chmod 755 $projdir
		    fi
		fi
	    else
		echo "OHhh all this work for nothing $projdir not mounted can't save info"
		exit 1
	    fi
	fi

    # start XXX
    # decided to change names again, rename if old names -- XXX remove this after all node have run the new code
    # take into consideration if old directory structure was added to to a new directory structure 
	if [ -d ${projdir}/$host ] ; then
	    owd=$PWD
	    cd ${projdir}/$host
	    [[ -L $host.full ]] && rm $host.full
	    [[ -L $host.diff ]] && rm $host.diff
	    for i in full diff tbdb ; do
		if [ -d $i ] ; then
		    [[ ! -d .$i ]] && (mkdir .$i ; chmod g+x .$i)
		    list=$(ls -A $i)
		    for j in $list ; do
			mv $i/$j .$i
		    done
		    rmdir $i
		fi
	    done
	    cd $owd
	fi
    # end XXX

    # have needed dirs ?
	[[ ! -d ${projdir}/$host ]] && ( mkdir -p ${projdir}/$host ; chmod g+x ${projdir}/$host )
	[[ ! -d ${projdir}/$host/.tbdb ]] && ( mkdir -p ${projdir}/$host/.tbdb ; chmod g+x ${projdir}/$host/.tbdb )
	[[ ! -d ${projdir}/$host/.full ]] && ( mkdir -p ${projdir}/$host/.full ; chmod g+x ${projdir}/$host/.full )
	[[ ! -d ${projdir}/$host/.diff ]] && ( mkdir -p ${projdir}/$host/.diff ; chmod g+x ${projdir}/$host/.diff )
	[[ ! -d ${projdir}/$host/.tmcc ]] && ( mkdir -p ${projdir}/$host/.tmcc ; chmod g+x ${projdir}/$host/.tmcc )

    # copy over the files including timestamps
	cp /tmp/nodecheck.log.tb.new ${projdir}/$host/.tbdb/$timestamp
	cp /tmp/nodecheck.log.inv ${projdir}/$host/.full/$timestamp

    # remove old symlinks and make new ones
	owd=$PWD
	cd ${projdir}/$host
	[[ -L $host ]] && rm -f $host #this should be a symlink
	[[ -L node ]] && rm -f node #this should be a symlink
	[[ -L full ]] && rm -f full #another symlink
	[[ -L tmcc ]] && rm -f tmcc #another symlink
	[[ -L diff ]] && rm -f diff #another symlink
	ln -s .tbdb/${timestamp} ${projdir}/$host/$host
	ln -s .tbdb/${timestamp} ${projdir}/$host/node
	ln -s .full/$timestamp ${projdir}/$host/full
	cd $owd

    # make sure no sudo is needed for read
	chmod g+r ${projdir}/$host/.*/${timestamp}
    fi
    
    if (( $check_flag )) ; then
	cd ${projdir}/$host
	# save what tmcc says right now
	$($BINDIR/tmcc hwinfo > ${projdir}/$host/.tmcc/$timestamp)
	ln -s .tmcc/$timestamp ${projdir}/$host/tmcc
	cd $owd

        # Test what was found locally against what is in the database
	readtmcinfo tmcc hwinvcopy # info from tmcc.bin hwinv
            # if testing can do something like    readtmcinfo ${projdir}/test
	readtmcinfo /tmp/nodecheck.log.inv hwinv # read full listing of locally found into hwinv
	# diff for local stuff not in tbdb
	comparetmcinfo /tmp/nodecheck.diff # file for output

        # if we ended up with a diff file handle it
	if [ -s /tmp/nodecheck.diff ] ; then
# show it at runtime??	cat /tmp/nodecheck.diff
	    # header
	    printf "\nDiff Report for %s @ %s\nKernel %s\n" "$host" "$(date)" "$(uname -srvm)" >> ${projdir}/$host/.diff/${timestamp}
	    echo "------------------------------------------------------------------" >> ${projdir}/$host/.diff/${timestamp}
	    # body
	    cat /tmp/nodecheck.diff >> ${projdir}/$host/.diff/${timestamp}
	    # link it
	    cd  ${projdir}/$host
	    [[ -L diff ]] && rm -f diff
	    ln -s .diff/${timestamp} ${projdir}/${host}/diff
	    cd $owd
	else
	    # no diff maybe it got better, put a marker out
	    cp /dev/null ${projdir}/${host}/.diff/${timestamp}
	fi
	chmod g+r ${projdir}/$host/.diff/${timestamp}
    fi

    [[ -f /tmp/nodecheck.log.inv ]] && rm /tmp/nodecheck.log.inv
    [[ -f /tmp/nodecheck.log.tb.new ]] && rm /tmp/nodecheck.log.tb.new 
    [[ -f /tmp/nodecheck.diff ]] && rm /tmp/nodecheck.diff
187
188

    return 0
189
190
191
192
193
194
}

initialize $@

(( $mfsmode )) && gatherinv_main $@ || nodecheck_main $@ 
postprocessing