forked from dcbradley/parrot_glidein_wrapper
-
Notifications
You must be signed in to change notification settings - Fork 4
/
parrot_setup
executable file
·299 lines (229 loc) · 11.1 KB
/
parrot_setup
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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/bin/sh -x
glidein_config="$1"
function warn {
echo `date` parrot_setup: $@ 1>&2
}
function die {
errorType="$1"
shift
warn ERROR: "$@"
"$error_gen" -error parrot_setup "$errorType" "$@"
exit 1
}
###########################################################
# import add_config_line and add_condor_vars_line functions
add_config_line_source=`grep '^ADD_CONFIG_LINE_SOURCE ' $glidein_config | awk '{print $2}'`
source $add_config_line_source
condor_vars_file=`grep -i "^CONDOR_VARS_FILE " $glidein_config | awk '{print $2}'`
# find error reporting helper script
error_gen=`grep '^ERROR_GEN_PATH ' $glidein_config | awk '{print $2}'`
# this case is for <file> in the factory config
GLIDEIN_PARROT=`grep -i "^GLIDEIN_PARROT " $glidein_config | awk '{print $2}'`
# this case is for <file> in the top-level scope of the frontend config
tmp_glidein_parrot=`grep -i "^GLIDECLIENT_GLIDEIN_PARROT " $glidein_config | awk '{print $2}'`
if [ -n "$tmp_glidein_parrot" ]; then
GLIDEIN_PARROT=$tmp_glidein_parrot
fi
# this case is for <file> in the group scope of the frontend config
tmp_glidein_parrot=`grep -i "^GLIDECLIENT_GROUP_GLIDEIN_PARROT " $glidein_config | awk '{print $2}'`
if [ -n "$tmp_glidein_parrot" ]; then
GLIDEIN_PARROT=$tmp_glidein_parrot
fi
if [ -z "$GLIDEIN_PARROT" ]; then
die VO_Config "No GLIDECLIENT_GLIDEIN_PARROT or GLIDECLIENT_GROUP_GLIDEIN_PARROT found in glidein config. This could indicate that parrot.tgz was not included in the glidein files or absdir_outattr for this tarball was not set to GLIDEIN_PARROT."
fi
# configure parrot temp directory
# this case is for <temp dir> in the factory config
GLIDEIN_PARROT_TMP=`grep -i "^GLIDEIN_PARROT_TMP " $glidein_config | awk '{print $2}'`
# this case is for <temp_dir> in the top-level scope of the frontend config
parrot_temp_dir=`grep -i "^GLIDECLIENT_GLIDEIN_PARROT_TMP " $glidein_config | awk '{print $2}'`
if [ -n "$parrot_temp_dir" ]; then
GLIDEIN_PARROT_TMP=$parrot_temp_dir
fi
# this case is for <file> in the group scope of the frontend config
parrot_temp_dir=`grep -i "^GLIDECLIENT_GROUP_GLIDEIN_PARROT_TMP " $glidein_config | awk '{print $2}'`
if [ -n "$parrot_temp_dir" ]; then
GLIDEIN_PARROT_TMP=$parrot_temp_dir
fi
# If not specified in the configs anywhere, set a default value
if [ -z "$GLIDEIN_PARROT_TMP" ]; then
GLIDEIN_PARROT_TMP="${GLIDEIN_PARROT}/tmp1"
echo "No TMP directory found; using \"${GLIDEIN_PARROT_TMP}\""
fi
echo "Using temp directory of \"$GLIDEIN_PARROT_TMP\""
add_config_line GLIDEIN_PARROT_TMP "$GLIDEIN_PARROT_TMP"
# Add the variable to the condor environment so that we can access it in the wrapper scripts
add_condor_vars_line GLIDEIN_PARROT_TMP "S" "-" "+" N Y "+"
if [ -z "$temp_dir" ]; then
# this case is for <file> in the group scope of the frontend config
temp_dir=`grep -i "^GLIDECLIENT_GROUP_GLIDEIN_PARROT_TMP " $glidein_config | awk '{print $2}'`
fi
# configure parrot alien cache directory
# this case is for <temp dir> in the factory config
GLIDEIN_PARROT_ALIEN=`grep -i "^GLIDEIN_PARROT_ALIEN " $glidein_config | awk '{print $2}'`
# this case is for <temp_dir> in the top-level scope of the frontend config
parrot_temp_dir=`grep -i "^GLIDECLIENT_GLIDEIN_PARROT_ALIEN " $glidein_config | awk '{print $2}'`
if [ -n "$parrot_temp_dir" ]; then
GLIDEIN_PARROT_ALIEN=$parrot_temp_dir
fi
# this case is for <file> in the group scope of the frontend config
parrot_temp_dir=`grep -i "^GLIDECLIENT_GROUP_GLIDEIN_PARROT_ALIEN" $glidein_config | awk '{print $2}'`
if [ -n "$parrot_temp_dir" ]; then
GLIDEIN_PARROT_ALIEN=$parrot_temp_dir
fi
# If not specified in the configs anywhere, set a default value
if [ -z "$GLIDEIN_PARROT_ALIEN" ]; then
GLIDEIN_PARROT_ALIEN="${GLIDEIN_PARROT_TMP}/alien_cache"
echo "No alien_cache directory found; using \"${GLIDEIN_PARROT_ALIEN}\""
fi
echo "Using alien cache directory of \"$GLIDEIN_PARROT_ALIEN\""
add_config_line GLIDEIN_PARROT_ALIEN "$GLIDEIN_PARROT_ALIEN"
# Add the variable to the condor environment so that we can access it in the wrapper scripts
add_condor_vars_line GLIDEIN_PARROT_ALIEN "S" "-" "+" N Y "+"
# Is there a better way to find parrot_cfg?
parrot_cfg=$(find $(pwd) -name parrot_cfg)
if [ "$parrot_cfg" = "" ] || ! [ -f "$parrot_cfg" ]; then
die VO_Config "No parrot_cfg found under `pwd`"
fi
add_config_line PARROT_CFG "$parrot_cfg"
source "$parrot_cfg"
# Mark parrot as non-functional until we test it below
add_config_line PARROT_RUN_WORKS FALSE
# find the unpacked parrot.tgz tarball location
# untar location GLIDECLIENT_GLIDEIN_PARROT is directory containing untarred files
# point GLIDEIN_PARROT inside the directory contained within the tar file:
#GLIDEIN_PARROT="$GLIDEIN_PARROT/parrot"
add_config_line GLIDEIN_PARROT "$GLIDEIN_PARROT"
# Unfortunately, the user can override GLIDEIN_PARROT and manipulate
# the wrapper, so instead of passing it to cvmfs_job_wrapper via the
# environment, we assume _CONDOR_SCRATCH_DIR will be a
# sub-(sub)-directory of the directory containing the following
# symlink:
ln -s $GLIDEIN_PARROT $(dirname $glidein_config)/GLIDEIN_PARROT
if [ -z "$temp_dir" ]; then
# this case is for <file> in the factory config
temp_dir=`grep -i "^GLIDEIN_PARROT " $glidein_config | awk '{print $2}'`
fi
if [ -z "$temp_dir" ]; then
die VO_Config "No GLIDECLIENT_GLIDEIN_PARROT or GLIDECLIENT_GROUP_GLIDEIN_PARROT found in glidein config. This could indicate that parrot.tgz was not included in the glidein files or absdir_outattr for this tarball was not set to GLIDEIN_PARROT."
fi
# configure CVMFS
# load balance across central proxies, if we use them
central_cvmfs_proxies="$CVMFS_PROXIES"
site_proxy=`grep -i "^PROXY_URL " $glidein_config | awk '{print $2}'`
if [ "$site_proxy" = "None" ]; then
site_proxy=""
fi
if [ "$site_proxy" != "" ]; then
warn "((((((((((((((((((((((((((("
warn "Testing access to $CVMFS_TEST_REPO via proxy $site_proxy"
wget_succeeded=0
for attempt in 1 2 3; do
if [ $attempt -gt 1 ]; then
sleep 1
fi
wget_output=$(env http_proxy="$site_proxy" wget -qdO /dev/null $CVMFS_TEST_REPO/.cvmfspublished 2>&1)
wget_rc=$?
echo "$wget_output"
age=$(echo "$wget_output" | grep '^Age: *[1-9]')
if [ "$wget_rc" != "0" ]; then
warn "WARNING: proxy $http_proxy did NOT succeed in wget test, so not using it"
break
elif [ "$age" != "" ]; then
warn "proxy $http_proxy succeeded in wget test"
wget_succeeded=1
break
else
# this could mean the file was not already cached or the proxy does
# not cache, so try 3 times before giving up
warn "proxy $http_proxy retrieved file but non-zero age not detected (attempt $attempt): $age"
fi
done
if [ $wget_succeeded != 1 ]; then
warn "WARNING: will not use proxy $http_proxy for CVMFS, using central proxies instead"
site_proxy=""
fi
warn ")))))))))))))))))))))))))))"
fi
if [ "$site_proxy" != "" ]; then
# only fail-over to central proxies if site proxy fails
cvmfs_proxies="proxies=$site_proxy;$central_cvmfs_proxies"
else
# no site proxy
cvmfs_proxies="proxies=$central_cvmfs_proxies"
fi
PARROT_CVMFS_REPO="${PARROT_CVMFS_REPO},${cvmfs_proxies}"
PARROT_CVMFS_REPO=$(echo "$PARROT_CVMFS_REPO" | sed "s|GLIDEIN_PARROT_DIR|$GLIDEIN_PARROT|g")
export PARROT_CVMFS_REPO
echo "export PARROT_CVMFS_REPO=\"${PARROT_CVMFS_REPO}\"" > $GLIDEIN_PARROT/setup.sh \
|| die WN_Resource "failed to create parrot/setup.sh"
PARROT_CVMFS_CONFIG="${PARROT_CVMFS_CONFIG}"
PARROT_CVMFS_CONFIG=$(echo "$PARROT_CVMFS_CONFIG" | sed "s|GLIDEIN_PARROT_DIR|$GLIDEIN_PARROT|g")
export PARROT_CVMFS_CONFIG
echo "export PARROT_CVMFS_CONFIG=\"${PARROT_CVMFS_CONFIG}\"" >> $GLIDEIN_PARROT/setup.sh \
|| die WN_Resource "failed to create parrot/setup.sh (PARROT_CVMFS_CONFIG=${PARROT_CVMFS_CONFIG})"
# Copy optional parrot options from parrot_cfg to the glidein config file
if ! [ -z "$GLIDEIN_PARROT_OPTIONS" ]; then
echo "GLIDEIN_PARROT_OPTIONS=\"${GLIDEIN_PARROT_OPTIONS}\"" >> $GLIDEIN_PARROT/setup.sh \
|| die WN_Resource "failed to append to parrot/setup.sh"
fi
if ! [ -z "$GlideinUseParrotIDBox" ]; then
echo "GlideinUseParrotIDBox=\"${GlideinUseParrotIDBox}\"" >> $GLIDEIN_PARROT/setup.sh \
|| die WN_Resource "failed to append to parrot/setup.sh"
fi
if [ "$GlideinAllowSwitchingCVMFSRepositories" != "false" ]; then
echo "export PARROT_ALLOW_SWITCHING_CVMFS_REPOSITORIES=1" >> $GLIDEIN_PARROT/setup.sh \
|| die WN_Resource "failed to append to parrot/setup.sh"
fi
if [ "$CVMFS_OSG_APP" != "" ]; then
# add CVMFS_OSG_APP to the job wrapper environment
add_config_line CVMFS_OSG_APP $CVMFS_OSG_APP
add_condor_vars_line CVMFS_OSG_APP "S" "-" "+" "N" "N" "+"
fi
FORCE_PARROT=0
if [ "$GlideinAlwaysUseParrotWrapper" != "" ] && [ "$GlideinAlwaysUseParrotWrapper" != "false" ]; then
# The wrapper script will check for this file to see if it should always apply the parrot wrapper
touch $GLIDEIN_PARROT/FORCE_PARROT
fi
warn "Attempting to run parrot_run and testing for existence of $CVMFS_TEST_PATH"
if ! mkdir -p "$GLIDEIN_PARROT_TMP" >& /dev/null || ! [ -w "$GLIDEIN_PARROT_TMP" ]; then
die WN_Resource "aborting glidein setup, because parrot temp dir ($GLIDEIN_PARROT_TMP) creation failed"
fi
if [ ! -e "$GLIDEIN_PARROT/parrot_run" ]; then
echo "Missing parrot_run; here's a listing of \$GLIDEIN_PARROT ($GLIDEIN_PARROT):"
ls -lh "$GLIDEIN_PARROT"
die Packaging "parrot_run binary is not unpacked into \"$GLIDEIN_PARROT\""
fi
$GLIDEIN_PARROT/parrot_run -v
if "$GLIDEIN_PARROT/parrot_run" -d cvmfs -t "$GLIDEIN_PARROT_TMP" test -e $CVMFS_TEST_PATH; then
# publish in the machine ad that this glidein supports parrot CVMFS
add_condor_vars_line HasParrotCVMFS "C" "True" "+" "N" "Y" "-"
# Publish to glidein_config that parrot_run is OK. May short-circuit CVMFS test.
add_config_line PARROT_RUN_WORKS TRUE
else
warn "test of parrot_run failed with exit status $?."
# do a simple wget test to see if that also fails
for http_proxy in `echo $cvmfs_proxies | sed 's/^proxies=//;s/[;|]/ /g;s|http://||g'`; do
export http_proxy
warn "((((((((((((((((((((((((((("
warn "Testing access to $CVMFS_TEST_REPO via proxy $http_proxy"
wget -O /dev/null $CVMFS_TEST_REPO/.cvmfspublished
if [ "$?" != "0" ]; then
warn "FAILURE: proxy $http_proxy did NOT succeed in wget test"
else
warn "proxy $http_proxy succeeded in wget test"
fi
warn ")))))))))))))))))))))))))))"
done
if [ "$GlideinRequiresParrotCVMFS" != "" ] && [ "$GlideinRequiresParrotCVMFS" != "false" ]; then
die WN_Resource "aborting glidein setup, because parrot setup failed and was required"
fi
# Do not let jobs requiring CVMFS run here
GLIDECLIENT_Start=`grep -i "^GLIDECLIENT_Start " $glidein_config | cut -d " " -f 2-`
if [ "$GLIDECLIENT_Start" != "" ]; then
GLIDECLIENT_Start="($GLIDECLIENT_Start) && "
fi
GLIDECLIENT_Start="${GLIDECLIENT_Start}TARGET.RequiresCVMFS=!=True"
add_config_line GLIDECLIENT_Start "$GLIDECLIENT_Start"
fi
"$error_gen" -ok parrot_setup