CE-cms-env 7.55 KB
Newer Older
Andrea Sciaba's avatar
Andrea Sciaba committed
1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/bash
#
# CE-cms-env
#
# This test does the following things:
# - prints some preliminary information
# - checks that the WN complies with some CMS requirements
# - checks that a software area is defined and exists
# - checks that the software area is writable with the lcgadmin role, 
#   if the siteis not CERN and is not using CERNVM-FS
# - prints the type and version of middleware
# - the required version of lcg-cp is installed
Christoph Wissing's avatar
Christoph Wissing committed
13
# - checks for gfal-copy, informal print out only
14
# String exit codes:
Andrea Sciaba's avatar
Andrea Sciaba committed
15
16
17
18
# NO_CERT_DIR: did not find the X.509 certificate directory
# NO_PROXY: did not find the proxy
# CANT_CREATE_DIR: cannot create a subdirectory
# NO_COPY_PROXY: cannot copy proxy in subdirectory
19
20
21
# SW_DIR_UNDEF: location of CMS software directory undefined
# SW_DIR_NOT_READABLE: CMS software directory not existent or unreadable
# SW_DIR_NOT_WRITABLE: the CMS software area is not writable when it should
Andrea Sciaba's avatar
Andrea Sciaba committed
22
23
24
# WORKDIR_LOW_SPACE: less than 10 GB of free spae in working directory
# TMP_LOW_SPACE: less than 10 MB space in /tmp
# TMP_LOW_QUOTA: less than 10 GB of free quota
25
26
# STAGEOUT_CMD_INVALID: the version of the stageout command is too old
# OK: everything is OK
Andrea Sciaba's avatar
Andrea Sciaba committed
27

Andrea Sciaba's avatar
Andrea Sciaba committed
28
cat `dirname $0`/CMS-SAM-Banner.txt
Andrea Sciaba's avatar
Andrea Sciaba committed
29
30
export LANG=C

Andrea Sciaba's avatar
Andrea Sciaba committed
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function check_df {
    dir=$1
    free=`df -P -B1MB $dir | awk '{if (NR==2) print $4}'`
    echo $free
    return 0
}

function check_quota {
    dir=$1
    fs=`df -kP $dir | awk '{if (NR==2) print $1}'`
    myquotastr=`quota 2>/dev/null | awk '{if (NR>2) {if (NF==1) {n=$1; getline; print n " " $2-$1} else {print $1 " " $3-$2}}}' |grep $fs`
    if [ $? -eq 0 ]; then
	# check only if there are any quotas, else ignore
	myquota=`echo $myquotastr|awk '{print $2}'`
	let "quotagb=$myquota / (2 * 1000)"
	echo $quotagb
    fi
    echo -1
    return 0
}

52
warn=0
Christoph Wissing's avatar
Christoph Wissing committed
53
54
info=0

Andrea Sciaba's avatar
Andrea Sciaba committed
55
56
echo "Printing preliminary information..."
echo
Andrea Sciaba's avatar
Andrea Sciaba committed
57
echo -n "Sysinfo: "
Andrea Sciaba's avatar
Andrea Sciaba committed
58
uname -a
Andrea Sciaba's avatar
Andrea Sciaba committed
59
/usr/bin/lsb_release -idrc
Andrea Sciaba's avatar
Andrea Sciaba committed
60
61
62
63
64
65
echo -n "LocalDate: "
date
echo -n "UTCDate: "
date --utc
echo -n "UserId: "
id
Andrea Sciaba's avatar
Andrea Sciaba committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
cat /proc/meminfo | grep Mem

# Checking some X509 details
if [ -e "$X509_CERT_DIR" ]; then
    cert_dir=$X509_CERT_DIR
elif [ -e "$HOME/.globus/certificates/" ]; then
	  cert_dir=$HOME/.globus/certificates/
elif [ -e "/etc/grid-security/certificates/" ]; then
    cert_dir=/etc/grid-security/certificates/
else
    echo "ERROR: could not find X509 certificate directory"
    echo "summary: NO_CERT_DIR"
    exit $SAME_ERROR
fi
echo "CertDir: $cert_dir"

if [ -a "$X509_USER_PROXY" ]; then
    proxy=$X509_USER_PROXY
84
85
elif [ -a "/tmp/x509up_u`id -u`" ]; then
    proxy="/tmp/x509up_u`id -u`"
Andrea Sciaba's avatar
Andrea Sciaba committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
else
    echo "ERROR: could not find X509 proxy certificate"
    echo "summary: NO_PROXY"
    exit $SAME_ERROR
fi
echo "Proxy: $proxy"

# Check proxy copy as in glidein pilots
local_proxy_dir=`pwd`/ticket
mkdir $local_proxy_dir
if [ $? -ne 0 ]; then
    echo "ERROR: could not find create $local_proxy_dir"
    echo "summary: CANT_CREATE_DIR"
    exit $SAME_ERROR
fi
cp $X509_USER_PROXY $local_proxy_dir/myproxy
if [ $? -ne 0 ]; then
    echo "ERROR: could not copy proxy $X509_USER_PROXY"
    echo "summary: NO_COPY_PROXY"
    exit $SAME_ERROR
fi
rm -rf $local_proxy_dir

Andrea Sciaba's avatar
Andrea Sciaba committed
109
110
111
type -t voms-proxy-info > /dev/null
result=$?
if [ $result -eq 0 ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
112
    isvoms=1
Andrea Sciaba's avatar
Andrea Sciaba committed
113
114
    echo -n "UserDN: "
    voms-proxy-info -identity
Andrea Sciaba's avatar
Andrea Sciaba committed
115
116
    l=`voms-proxy-info -timeleft`
    echo "Timeleft: $l s"
Andrea Sciaba's avatar
Andrea Sciaba committed
117
    fqan=`voms-proxy-info -fqan`
Andrea Sciaba's avatar
Andrea Sciaba committed
118
119
    echo "FQAN:"
    echo "$fqan"
Andrea Sciaba's avatar
Andrea Sciaba committed
120
else
Andrea Sciaba's avatar
Andrea Sciaba committed
121
    isvoms=0
Andrea Sciaba's avatar
Andrea Sciaba committed
122
123
    echo "WARNING: voms-proxy-info not found"
fi
Andrea Sciaba's avatar
Andrea Sciaba committed
124
125
126
if [ $isvoms -eq 1 -a $l -lt 21600 ] ; then
    echo "WARNING: proxy shorther than 6 hours"
fi    
Andrea Sciaba's avatar
Andrea Sciaba committed
127
128
129
130
131
132
133
134

# Test of the local worker node environment
echo
echo "Checking local worker node environment..."
echo

# Software area definition and existence
isEGEE=0
Andrea Sciaba's avatar
Andrea Sciaba committed
135
if [ -n "$OSG_GRID" ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
136
    [ -f $OSG_GRID/setup.sh ] && source $OSG_GRID/setup.sh
Andrea Sciaba's avatar
Andrea Sciaba committed
137
138
139
140
141
142
143
144
145
146
147
    if [ -d $OSG_APP/cmssoft/cms ] ;then
        SW_DIR=$OSG_APP/cmssoft/cms
    elif [ -d $CVMFS/cms.cern.ch ] ; then
        SW_DIR=$CVMFS/cms.cern.ch
    elif [ -d /cvmfs/cms.cern.ch ] ; then
        SW_DIR=/cvmfs/cms.cern.ch
    else
        echo "ERROR: Cannot find CMS software in OSG node"
	echo "summary: SW_DIR_UNDEF"
        exit $SAME_ERROR
    fi
Andrea Sciaba's avatar
Andrea Sciaba committed
148
149
150
151
152
153
    echo "SwArea: $SW_DIR"
elif [ -n "$VO_CMS_SW_DIR" ] ; then
    isEGEE=1
    SW_DIR=$VO_CMS_SW_DIR
    echo "SwArea: $SW_DIR"
else
154
    SW_DIR=/cvmfs/cms.cern.ch
Andrea Sciaba's avatar
Andrea Sciaba committed
155
fi
156
if [ ! -d $SW_DIR -o ! -r $SW_DIR ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
157
158
    echo "ERROR: software directory non existent or non readable"
    echo "summary: SW_DIR_NOT_READABLE"
159
    exit $SAME_ERROR
Andrea Sciaba's avatar
Andrea Sciaba committed
160
161
162
163
164
165
fi

# Software area space
hasCVMFS=0
if [ -d $SW_DIR ] ; then
  if [ "`echo $SW_DIR | cut -d / -f 2`" == "afs" ]; then
Andrea Sciaba's avatar
Andrea Sciaba committed
166
    SPACE=`fs lq $SW_DIR | tail -1 | awk '{print (\$2-\$3)/1000000 }'`
Andrea Sciaba's avatar
Andrea Sciaba committed
167
168
169
  elif [ "`echo $SW_DIR | cut -d / -f 2`" == "cvmfs" ]; then
    hasCVMFS=1
  else
Andrea Sciaba's avatar
Andrea Sciaba committed
170
    SPACE=`df -k -P $SW_DIR | tail -1 | awk '{print \$4/1000000}'`
Andrea Sciaba's avatar
Andrea Sciaba committed
171
172
  fi
  if [ $hasCVMFS == 0  ]; then
Andrea Sciaba's avatar
Andrea Sciaba committed
173
    echo "FreeSWAreaSpace: $SPACE GB"
Andrea Sciaba's avatar
Andrea Sciaba committed
174
175
176
  fi
fi

Andrea Sciaba's avatar
Andrea Sciaba committed
177
178
179
180
# Check for free space on current directory and /tmp
space=`check_df .`
echo "WorkDirSpace: $space MB"
if [ $space -lt 10000 ] ; then
181
182
183
    echo "WARNING: less than 10 GB of free space in working directory"
    summary="summary: WORKDIR_LOW_SPACE"
    warn=1
Andrea Sciaba's avatar
Andrea Sciaba committed
184
185
186
187
188
fi

space=`check_df /tmp`
echo "TmpSpace: $space MB"
if [ $space -lt 10 ] ; then
189
190
191
    echo "WARNING: less than 10 MB of free space in /tmp"
    summary="summary: TMP_LOW_SPACE"
    warn=1
Andrea Sciaba's avatar
Andrea Sciaba committed
192
193
194
195
196
197
198
fi

# Check quota, if any
space=`check_quota .`
if [ $space -ne -1 ] ; then
    echo "Quota: $space MB"
    if [ $space -lt 10000 ] ; then
199
200
201
	echo "WARNING: too little quota"
	summary="summary: TMP_LOW_QUOTA"
	warn=1
Andrea Sciaba's avatar
Andrea Sciaba committed
202
203
204
    fi
fi

205
206
# check for SL5
echo
Andrea Sciaba's avatar
Andrea Sciaba committed
207
echo "Checking OS version from $SW_DIR/common/cmsos and architecture from $SW_DIR/common/cmsarch..."
208
209
210
211
212
213
214
215
216
217
218
echo
slVersion="unknown"
if [ -f $SW_DIR/common/cmsos ] ; then
 osVersion=`$SW_DIR/common/cmsos`
 echo "osVersion: " $osVersion
 cmsarch=`$SW_DIR/common/cmsarch`
 echo "scram_arch: " $cmsarch
 slVersion=`echo $cmsarch|cut -d'_' -f1`
fi
echo "slVersion: " $slVersion

Andrea Sciaba's avatar
Andrea Sciaba committed
219
220
221
echo
echo "Checking middleware installation..."
echo
222
223
mw=0
if type -f glite-version > /dev/null 2>&1; then
Andrea Sciaba's avatar
Andrea Sciaba committed
224
225
    type="gLite"
    mwver=`glite-version`
226
    mw=1
Andrea Sciaba's avatar
Andrea Sciaba committed
227
228
229
elif [ -f /etc/emi-version ] ; then
    type="EMI"
    mwver=`cat /etc/emi-version`
230
    mw=1
231
232
233
234
elif [ -f $EMI_UI_CONF/etc/emi-version ] ; then
    type="EMI"
    mwver=`cat $EMI_UI_CONF/etc/emi-version`
    mw=1
235
elif type -f lcg-version > /dev/null 2>&1; then
Andrea Sciaba's avatar
Andrea Sciaba committed
236
237
    type="LCG"
    mwver=`lcg-version`
238
239
240
241
242
    mw=1
fi
if [ $mw == 1 ] ; then
    echo "Middleware: $type $mwver"
else
Andrea Sciaba's avatar
Andrea Sciaba committed
243
    echo "WARNING: Cannot find middleware stack type and version"
Andrea Sciaba's avatar
Andrea Sciaba committed
244
fi
Andrea Sciaba's avatar
Andrea Sciaba committed
245
echo
Andrea Sciaba's avatar
Andrea Sciaba committed
246
247
248

type -t lcg-cp > /dev/null
result=$?
249
stageout=1
Andrea Sciaba's avatar
Andrea Sciaba committed
250
if [ $result -ne 0 ] ; then
251
    echo "WARNING: lcg-cp not in the PATH"
Andrea Sciaba's avatar
Andrea Sciaba committed
252
253
254
255
256
257
else
    lcgutilver=`lcg-cp --version | grep lcg_util | sed 's/lcg_util-//'`
    echo "lcg_util: $lcgutilver"
    gfalver=`lcg-cp --version | grep GFAL-client | sed 's/GFAL-client-//'`
    echo "GFAL-client: $gfalver"
    lver=(`echo $lcgutilver | awk -F . '{print $1*10000+$2*100+$3}'`)
Andrea Sciaba's avatar
Andrea Sciaba committed
258
    echo -n "Minimum version of lcg-cp: 1.6.7: "
Andrea Sciaba's avatar
Andrea Sciaba committed
259
    if [ $lver -ge 10607 ] ; then
260
	stageout=0
Andrea Sciaba's avatar
Andrea Sciaba committed
261
262
263
	echo "OK"
    else
	echo
264
	echo "WARNING: lcg-cp older than 1.6.7"
Andrea Sciaba's avatar
Andrea Sciaba committed
265
266
    fi
fi
Christoph Wissing's avatar
Christoph Wissing committed
267
268
269
270

type -t gfal-copy > /dev/null
result=$?
if [ $result -ne 0 ] ; then
271
    echo "WARNING: gfal-copy not in the PATH"
Christoph Wissing's avatar
Christoph Wissing committed
272
273
274
else
    gfalver=`gfal-copy -V 2>&1`
    echo "GFAL2 clients: $gfalver"
275
276
277
278
279
280
    stageout=0
fi
if [ $stageout == 1 ] ; then
    echo "ERROR: no valid command for remote stageout"
    echo "summary: STAGEOUT_CMD_INVALID"
    exit $SAME_ERROR
Christoph Wissing's avatar
Christoph Wissing committed
281
fi
Andrea Sciaba's avatar
Andrea Sciaba committed
282
echo
283
284
285
286
if [ $warn == 1 ] ; then
    echo $summary
    exit $SAME_WARNING
fi
Christoph Wissing's avatar
Christoph Wissing committed
287
288
if [ $info == 1 ] ; then
    echo $summary
Andrea Sciaba's avatar
Andrea Sciaba committed
289
    exit $SAME_OK
Christoph Wissing's avatar
Christoph Wissing committed
290
fi
Andrea Sciaba's avatar
Andrea Sciaba committed
291
292
293
echo "All checks OK"
echo "summary: OK"
exit $SAME_OK
294