CE-cms-env 7.53 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
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}'`
Andrea Sciaba's avatar
Andrea Sciaba committed
41
    myquotastr=`timeout 15 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`
Andrea Sciaba's avatar
Andrea Sciaba committed
42
43
44
45
    if [ $? -eq 0 ]; then
	# check only if there are any quotas, else ignore
	myquota=`echo $myquotastr|awk '{print $2}'`
	let "quotagb=$myquota / (2 * 1000)"
Andrea Sciaba's avatar
Andrea Sciaba committed
46
47
    else
        echo -1
Andrea Sciaba's avatar
Andrea Sciaba committed
48
49
50
51
    fi
    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
112
113
type -t voms-proxy-info > /dev/null
result=$?
if [ $result -eq 0 ] ; then
    echo -n "UserDN: "
    voms-proxy-info -identity
Andrea Sciaba's avatar
Andrea Sciaba committed
114
115
    l=`voms-proxy-info -timeleft`
    echo "Timeleft: $l s"
Andrea Sciaba's avatar
Andrea Sciaba committed
116
    fqan=`voms-proxy-info -fqan`
Andrea Sciaba's avatar
Andrea Sciaba committed
117
118
    echo "FQAN:"
    echo "$fqan"
Andrea Sciaba's avatar
Andrea Sciaba committed
119
120
121
    if [ $l -lt 21600 ] ; then
        echo "WARNING: proxy shorther than 6 hours"
    fi
Andrea Sciaba's avatar
Andrea Sciaba committed
122
123
124
125
126
127
128
129
130
131
132
else
    echo "WARNING: voms-proxy-info not found"
fi

# 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
133
if [ -n "$OSG_GRID" ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
134
    [ -f $OSG_GRID/setup.sh ] && source $OSG_GRID/setup.sh
Andrea Sciaba's avatar
Andrea Sciaba committed
135
136
137
138
139
140
141
142
143
144
145
    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
146
147
148
149
150
151
    echo "SwArea: $SW_DIR"
elif [ -n "$VO_CMS_SW_DIR" ] ; then
    isEGEE=1
    SW_DIR=$VO_CMS_SW_DIR
    echo "SwArea: $SW_DIR"
else
152
    SW_DIR=/cvmfs/cms.cern.ch
Andrea Sciaba's avatar
Andrea Sciaba committed
153
fi
154
if [ ! -d $SW_DIR -o ! -r $SW_DIR ] ; then
Andrea Sciaba's avatar
Andrea Sciaba committed
155
156
    echo "ERROR: software directory non existent or non readable"
    echo "summary: SW_DIR_NOT_READABLE"
157
    exit $SAME_ERROR
Andrea Sciaba's avatar
Andrea Sciaba committed
158
159
160
161
162
163
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
164
    SPACE=`fs lq $SW_DIR | tail -1 | awk '{print (\$2-\$3)/1000000 }'`
Andrea Sciaba's avatar
Andrea Sciaba committed
165
166
167
  elif [ "`echo $SW_DIR | cut -d / -f 2`" == "cvmfs" ]; then
    hasCVMFS=1
  else
Andrea Sciaba's avatar
Andrea Sciaba committed
168
    SPACE=`df -k -P $SW_DIR | tail -1 | awk '{print \$4/1000000}'`
Andrea Sciaba's avatar
Andrea Sciaba committed
169
170
  fi
  if [ $hasCVMFS == 0  ]; then
Andrea Sciaba's avatar
Andrea Sciaba committed
171
    echo "FreeSWAreaSpace: $SPACE GB"
Andrea Sciaba's avatar
Andrea Sciaba committed
172
173
174
  fi
fi

Andrea Sciaba's avatar
Andrea Sciaba committed
175
176
177
178
# Check for free space on current directory and /tmp
space=`check_df .`
echo "WorkDirSpace: $space MB"
if [ $space -lt 10000 ] ; then
179
180
181
    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
182
183
184
185
186
fi

space=`check_df /tmp`
echo "TmpSpace: $space MB"
if [ $space -lt 10 ] ; then
187
188
189
    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
190
191
192
193
194
195
196
fi

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

203
204
# check for SL5
echo
Andrea Sciaba's avatar
Andrea Sciaba committed
205
echo "Checking OS version from $SW_DIR/common/cmsos and architecture from $SW_DIR/common/cmsarch..."
206
207
208
209
210
211
212
213
214
215
216
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
217
218
219
echo
echo "Checking middleware installation..."
echo
220
221
mw=0
if type -f glite-version > /dev/null 2>&1; then
Andrea Sciaba's avatar
Andrea Sciaba committed
222
223
    type="gLite"
    mwver=`glite-version`
224
    mw=1
Andrea Sciaba's avatar
Andrea Sciaba committed
225
226
227
elif [ -f /etc/emi-version ] ; then
    type="EMI"
    mwver=`cat /etc/emi-version`
228
    mw=1
229
230
231
232
elif [ -f $EMI_UI_CONF/etc/emi-version ] ; then
    type="EMI"
    mwver=`cat $EMI_UI_CONF/etc/emi-version`
    mw=1
233
elif type -f lcg-version > /dev/null 2>&1; then
Andrea Sciaba's avatar
Andrea Sciaba committed
234
235
    type="LCG"
    mwver=`lcg-version`
236
237
238
239
240
    mw=1
fi
if [ $mw == 1 ] ; then
    echo "Middleware: $type $mwver"
else
Andrea Sciaba's avatar
Andrea Sciaba committed
241
    echo "WARNING: Cannot find middleware stack type and version"
Andrea Sciaba's avatar
Andrea Sciaba committed
242
fi
Andrea Sciaba's avatar
Andrea Sciaba committed
243
echo
Andrea Sciaba's avatar
Andrea Sciaba committed
244
245
246

type -t lcg-cp > /dev/null
result=$?
247
stageout=1
Andrea Sciaba's avatar
Andrea Sciaba committed
248
if [ $result -ne 0 ] ; then
249
    echo "WARNING: lcg-cp not in the PATH"
Andrea Sciaba's avatar
Andrea Sciaba committed
250
251
252
253
254
255
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
256
    echo -n "Minimum version of lcg-cp: 1.6.7: "
Andrea Sciaba's avatar
Andrea Sciaba committed
257
    if [ $lver -ge 10607 ] ; then
258
	stageout=0
Andrea Sciaba's avatar
Andrea Sciaba committed
259
260
261
	echo "OK"
    else
	echo
262
	echo "WARNING: lcg-cp older than 1.6.7"
Andrea Sciaba's avatar
Andrea Sciaba committed
263
264
    fi
fi
Christoph Wissing's avatar
Christoph Wissing committed
265
266
267
268

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