-
Notifications
You must be signed in to change notification settings - Fork 10
/
runpilot2-wrapper.sh
executable file
·1205 lines (1094 loc) · 34.1 KB
/
runpilot2-wrapper.sh
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# pilot wrapper used at CERN central pilot factories
#
# https://google.github.io/styleguide/shell.xml
VERSION=20241111a-master
function err() {
dt=$(date --utc +"%Y-%m-%d %H:%M:%S,%3N [wrapper]")
echo "$dt $@" >&2
}
function log() {
dt=$(date --utc +"%Y-%m-%d %H:%M:%S,%3N [wrapper]")
echo "$dt $@"
}
function get_workdir {
if [[ ${piloturl} == 'local' && ${harvesterflag} == 'false' ]]; then
echo $(pwd)
return 0
fi
if [[ ${harvesterflag} == 'true' ]]; then
# test if Harvester WorkFlow is OneToMany aka "Jumbo" Jobs
if [[ ${workflowarg} == 'OneToMany' ]]; then
if [[ -n ${!harvesterarg} ]]; then
templ=$(pwd)/atlas_${!harvesterarg}
mkdir ${templ}
echo ${templ}
return 0
fi
else
echo $(pwd)
return 0
fi
fi
if [[ -n "${OSG_WN_TMP}" ]]; then
templ=${OSG_WN_TMP}/atlas_XXXXXXXX
elif [[ -n "${TMPDIR}" ]]; then
templ=${TMPDIR}/atlas_XXXXXXXX
else
templ=$(pwd)/atlas_XXXXXXXX
fi
tempd=$(mktemp -d $templ)
if [[ $? -ne 0 ]]; then
log "ERROR: mktemp failed: $templ"
err "ERROR: mktemp failed: $templ"
return 1
fi
echo ${tempd}
}
function check_python2() {
pybin=$(which python2)
if [[ $? -ne 0 ]]; then
log "FATAL: python2 not found in PATH"
err "FATAL: python2 not found in PATH"
if [[ -z "${PATH}" ]]; then
log "In fact, PATH env var is unset mon amie"
err "In fact, PATH env var is unset mon amie"
fi
log "PATH content is ${PATH}"
err "PATH content is ${PATH}"
apfmon_fault 1
sortie 1
fi
pyver=$($pybin -c 'import sys; print("%i%02i" % (sys.version_info.major, sys.version_info.minor))')
# we don't want python3 if requesting python2 explicitly
if [[ ${pyver} -ge 300 ]] ; then
log "ERROR: this site has python > 3.0, but only python2 requested"
err "ERROR: this site has python > 3.0, but only python2 requested"
apfmon_fault 1
sortie 1
fi
# check if native python version > 2.6
if [[ ${pyver} -ge 206 ]] ; then
log "Native python version is > 2.6 (${pyver})"
log "Using ${pybin} for python compatibility"
return
else
log "ERROR: this site has native python < 2.6"
err "ERROR: this site has native python < 2.6"
log "Native python ${pybin} is old: ${pyver}"
# Oh dear, we're doomed...
log "FATAL: Failed to find a compatible python, exiting"
err "FATAL: Failed to find a compatible python, exiting"
apfmon_fault 1
sortie 1
fi
}
function setup_python3() {
# setup python3 from ALRB, default for grid sites
if [[ ${localpyflag} == 'true' ]]; then
log "localpyflag is true so we skip ALRB python3"
elif [[ ${ATLAS_LOCAL_PYTHON} == 'true' ]]; then
# email thread 7/7/21 dealing with LRZ SUSE
log "Env var ATLAS_LOCAL_PYTHON=true so skip ALRB python3"
else
log "Using ALRB to setup python3"
if [ -z "$ATLAS_LOCAL_ROOT_BASE" ]; then
export ATLAS_LOCAL_ROOT_BASE="${ATLAS_SW_BASE}/atlas.cern.ch/repo/ATLASLocalRootBase"
fi
export ALRB_LOCAL_PY3="YES"
source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh --quiet >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
log "FATAL: failed to source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh"
err "FATAL: failed to source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh"
apfmon_fault 64
sortie 64
fi
if [ -z $ALRB_pythonVersion ]; then
lsetup -q "python pilot-default"
else
lsetup -q python
fi
fi
}
function check_python3() {
pybin=$(which python3)
if [[ $? -ne 0 ]]; then
log "FATAL: python3 not found in PATH"
err "FATAL: python3 not found in PATH"
if [[ -z "${PATH}" ]]; then
log "In fact, PATH env var is unset mon amie"
err "In fact, PATH env var is unset mon amie"
fi
log "PATH content: ${PATH}"
err "PATH content: ${PATH}"
apfmon_fault 1
sortie 1
fi
pyver=$($pybin -c 'import sys; print("%i%02i" % (sys.version_info.major, sys.version_info.minor))')
# check if python version > 3.6
if [[ ${pyver} -ge 306 ]] ; then
log "Python version is > 3.6 (${pyver})"
log "Using ${pybin} for python compatibility"
else
log "ERROR: this site has python < 3.6"
err "ERROR: this site has python < 3.6"
log "Python ${pybin} is old: ${pyver}"
# Oh dear, we're doomed...
log "FATAL: Failed to find a compatible python, exiting"
err "FATAL: Failed to find a compatible python, exiting"
apfmon_fault 1
sortie 1
fi
}
function check_proxy() {
voms-proxy-info -all
if [[ $? -ne 0 ]]; then
log "WARNING: error running: voms-proxy-info -all"
err "WARNING: error running: voms-proxy-info -all"
arcproxy -I
if [[ $? -eq 127 ]]; then
log "FATAL: error running: arcproxy -I"
err "FATAL: error running: arcproxy -I"
apfmon_fault 1
sortie 1
fi
fi
}
function check_cvmfs() {
export VO_ATLAS_SW_DIR=${VO_ATLAS_SW_DIR:-${ATLAS_SW_BASE}/atlas.cern.ch/repo/sw}
CVMFS_BASE=${ATLAS_SW_BASE:-/cvmfs}
targets="${CVMFS_BASE}/atlas.cern.ch/repo/ATLASLocalRootBase/logDir/lastUpdate \
${CVMFS_BASE}/atlas-condb.cern.ch/repo/conditions/logDir/lastUpdate \
${CVMFS_BASE}/atlas-nightlies.cern.ch/repo/sw/logs/lastUpdate \
${CVMFS_BASE}/sft.cern.ch/lcg/lastUpdate \
${CVMFS_BASE}/unpacked.cern.ch/logDir/lastUpdate \
${CVMFS_BASE}/sft-nightlies.cern.ch/lcg/lastUpdate"
for target in ${targets}; do
if [ $(cat ${target} | wc -l) -ge 1 ]; then
log "${target} is accessible"
else
log "WARNING: ${target} not accessible or empty, pilot to handle"
err "WARNING: ${target} not accessible or empty, pilot to handle"
# apfmon_fault 64
# sortie 64
fi
done
}
function setup_alrb() {
export ATLAS_LOCAL_ROOT_BASE=${ATLAS_LOCAL_ROOT_BASE:-${ATLAS_SW_BASE}/atlas.cern.ch/repo/ATLASLocalRootBase}
export ALRB_userMenuFmtSkip=YES
export ALRB_noGridMW=${ALRB_noGridMW:-NO}
log 'NOTE: rucio,davix,xrootd setup now done in local site setup atlasLocalSetup.sh'
if [[ ${iarg} == "RC" ]]; then
log 'RC pilot requested, setting ALRB_rucioVersion=testing'
log 'RC pilot, source $ATLAS_LOCAL_ROOT_BASE/etc/ADCPilotTesting.sh'
source $ATLAS_LOCAL_ROOT_BASE/etc/ADCPilotTesting.sh
export ALRB_rucioVersion=testing
fi
if [[ ${iarg} == "ALRB" ]]; then
log 'ALRB pilot requested, setting ALRB env vars to testing'
export ALRB_adcTesting=YES
fi
if [[ ${ALRB_noGridMW} == "YES" ]]; then
log "Site has set ALRB_noGridMW=YES so use site native install rather than ALRB"
if [[ ${tflag} == 'true' ]]; then
log 'Skipping proxy checks due to -t flag'
else
check_vomsproxyinfo || check_arcproxy
if [[ $? -eq 1 ]]; then
log "FATAL: Site MW being used but proxy tools not found"
err "FATAL: Site MW being used but proxy tools not found"
apfmon_fault 1
sortie 1
fi
fi
else
log "Will use ALRB MW because ALRB_noGridMW=NO (default)"
fi
}
function setup_local() {
log "Looking for ${VO_ATLAS_SW_DIR}/local/setup.sh"
if [[ -f ${VO_ATLAS_SW_DIR}/local/setup.sh ]]; then
if [[ ${pythonversion} == '3' ]]; then
log "Sourcing ${VO_ATLAS_SW_DIR}/local/setup.sh -s ${qarg} -p python3"
source ${VO_ATLAS_SW_DIR}/local/setup.sh -s ${qarg} -p python3
else
log "Sourcing ${VO_ATLAS_SW_DIR}/local/setup.sh -s ${qarg}"
source ${VO_ATLAS_SW_DIR}/local/setup.sh -s ${qarg}
fi
else
log 'WARNING: No ATLAS local setup found'
err 'WARNING: this site has no local setup ${VO_ATLAS_SW_DIR}/local/setup.sh'
fi
# OSG MW setup, skip if not using ALRB Grid MW
if [[ ${ALRB_noGridMW} == "YES" ]]; then
if [[ -f ${OSG_GRID}/setup.sh ]]; then
log "Setting up OSG MW using ${OSG_GRID}/setup.sh"
source ${OSG_GRID}/setup.sh
else
log 'Env var ALRB_noGridMW=NO, not sourcing ${OSG_GRID}/setup.sh'
fi
fi
}
function setup_shoal() {
log "will set FRONTIER_SERVER with shoal"
outputstr=$(env -i FRONTIER_SERVER="$FRONTIER_SERVER" /bin/bash -l -c "shoal-client -f")
if [[ $? -eq 0 ]] && [[ -n "${outputstr}" ]] ; then
export FRONTIER_SERVER=${outputstr}
else
log "WARNING: shoal-client had non-zero exit code or empty output"
fi
log "FRONTIER_SERVER = $FRONTIER_SERVER"
}
function setup_harvester_symlinks() {
for datafile in `find ${HARVESTER_WORKDIR} -maxdepth 1 -type l -exec /usr/bin/readlink -e {} ';'`; do
symlinkname=$(basename $datafile)
ln -s $datafile $symlinkname
done
}
function check_vomsproxyinfo() {
out=$(voms-proxy-info --version 2>/dev/null)
if [[ $? -eq 0 ]]; then
log "Check version: ${out}"
return 0
else
log "voms-proxy-info not found"
return 1
fi
}
function check_arcproxy() {
out=$(arcproxy --version 2>/dev/null)
if [[ $? -eq 0 ]]; then
log "Check version: ${out}"
return 0
else
log "arcproxy not found"
return 1
fi
}
function pilot_cmd() {
# test if not harvester job
if [[ ${harvesterflag} == 'false' ]] ; then
if [[ -n ${pilotversion} ]]; then
cmd="${pybin} ${pilotbase}/pilot.py -q ${qarg} -i ${iarg} -j ${jarg} ${pilotargs}"
else
cmd="${pybin} ${pilotbase}/pilot.py -q ${qarg} -i ${iarg} -j ${jarg} ${pilotargs}"
fi
else
# check to see if we are running OneToMany Harvester workflow (aka Jumbo Jobs)
if [[ ${workflowarg} == 'OneToMany' ]] && [ -z ${HARVESTER_PILOT_WORKDIR+x} ] ; then
cmd="${pybin} ${pilotbase}/pilot.py -q ${qarg} -i ${iarg} -j ${jarg} -a ${HARVESTER_PILOT_WORKDIR} ${pilotargs}"
else
cmd="${pybin} ${pilotbase}/pilot.py -q ${qarg} -i ${iarg} -j ${jarg} ${pilotargs}"
fi
fi
echo ${cmd}
}
function sing_cmd() {
cmd="$BINARY_PATH exec $SINGULARITY_OPTIONS --env \"APFCID=$APFCID\" \
--env \"APFFID=$APFFID\" \
--env \"HARVESTER_ID=$HARVESTER_ID\" \
--env \"HARVESTER_WORKER_ID=$HARVESTER_WORKER_ID\" \
--env \"PANDA_AUTH_ORIGIN=$PANDA_AUTH_ORIGIN\" \
--env \"PANDA_AUTH_TOKEN=$PANDA_AUTH_TOKEN\" \
--env \"PANDA_AUTH_TOKEN_KEY=$PANDA_AUTH_TOKEN_KEY\" \
$IMAGE_PATH $0 $myargs"
echo ${cmd}
}
function sing_env() {
export APPTAINERENV_X509_USER_PROXY=${X509_USER_PROXY}
if [[ -n "${ATLAS_LOCAL_AREA}" ]]; then
export APPTAINERENV_ATLAS_LOCAL_AREA=${ATLAS_LOCAL_AREA}
fi
if [[ -n "${TMPDIR}" ]]; then
export APPTAINERENV_TMPDIR=${TMPDIR}
fi
if [[ -n "${RECOVERY_DIR}" ]]; then
export APPTAINERENV_RECOVERY_DIR=${RECOVERY_DIR}
fi
if [[ -n "${GTAG}" ]]; then
export APPTAINERENV_GTAG=${GTAG}
fi
}
function get_piloturl() {
local version=$1
local pilotdir=file://${ATLAS_SW_BASE}/atlas.cern.ch/repo/sw/PandaPilot/tar
if [[ -n ${piloturl} ]]; then
echo ${piloturl}
return 0
fi
if [[ ${version} == '1' ]]; then
log "FATAL: pilot version 1 requested, not supported by this wrapper"
err "FATAL: pilot version 1 requested, not supported by this wrapper"
apfmon_fault 1
sortie 1
elif [[ ${version} == '2' ]]; then
log "FATAL: pilot version 2 requested, not supported by this wrapper"
err "FATAL: pilot version 2 requested, not supported by this wrapper"
apfmon_fault 1
sortie 1
elif [[ ${version} == 'latest' ]]; then
pilottar=${pilotdir}/pilot3.tar.gz
pilotbase='pilot3'
elif [[ ${version} == 'current' ]]; then
pilottar=${pilotdir}/pilot3.tar.gz
pilotbase='pilot3'
elif [[ ${version} == '3' ]]; then
pilottar=${pilotdir}/pilot3.tar.gz
pilotbase='pilot3'
else
pilottar=${pilotdir}/pilot3-${version}.tar.gz
pilotbase='pilot3'
fi
echo ${pilottar}
}
function get_pilot() {
local url=$1
# remove pending chk from Lincoln
if [[ ${harvesterflag} == 'true' ]] && [[ ${workflowarg} == 'OneToMany' ]]; then
cp -v ${HARVESTER_WORK_DIR}/pilot2.tar.gz .
fi
if [[ ${url} == 'local' ]]; then
log "piloturl=local so download not needed"
if [[ -f pilot3.tar.gz ]]; then
log "local tarball pilot3.tar.gz exists OK"
tar -xzf pilot3.tar.gz
if [[ $? -ne 0 ]]; then
log "ERROR: pilot extraction failed for pilot3.tar.gz"
err "ERROR: pilot extraction failed for pilot3.tar.gz"
return 1
fi
elif [[ -f pilot2.tar.gz ]]; then
log "local tarball pilot2.tar.gz exists OK"
log "FATAL: pilot version 2 requested, not supported by this wrapper"
err "FATAL: pilot version 2 requested, not supported by this wrapper"
return 1
else
log "local pilot[23].tar.gz not found so assuming already extracted"
fi
else
curl --connect-timeout 30 --max-time 180 -sSL ${url} | tar -xzf -
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
log "ERROR: pilot download failed: ${url}"
err "ERROR: pilot download failed: ${url}"
return 1
fi
fi
if [[ -f ${pilotbase}/pilot.py ]]; then
log "File ${pilotbase}/pilot.py exists OK"
log "${pilotbase}/PILOTVERSION: $(cat ${pilotbase}/PILOTVERSION)"
return 0
else
log "ERROR: ${pilotbase}/pilot.py not found"
err "ERROR: ${pilotbase}/pilot.py not found"
return 1
fi
}
function muted() {
log "apfmon messages muted"
}
function apfmon_running() {
[[ ${mute} == 'true' ]] && muted && return 0
echo -n "running 0 ${VERSION} ${qarg} ${APFFID}:${APFCID}" > /dev/udp/148.88.67.14/28527
echo -n "running 0 ${VERSION} ${qarg} ${HARVESTER_ID}:${HARVESTER_WORKER_ID} ${GTAG}" > /dev/udp/148.88.96.15/28527
resource=${GRID_GLOBAL_JOBHOST:-}
out=$(curl -ksS --connect-timeout 10 --max-time 20 -d uuid=${UUID} \
-d qarg=${qarg} -d state=wrapperrunning -d wrapper=${VERSION} \
-d gtag=${GTAG} -d resource=${resource} \
-d hid=${HARVESTER_ID} -d hwid=${HARVESTER_WORKER_ID} \
${APFMON}/jobs/${APFFID}:${APFCID})
if [[ $? -eq 0 ]]; then
log $out
else
err "WARNING: wrapper monitor ${UUID}"
fi
}
function apfmon_exiting() {
[[ ${mute} == 'true' ]] && muted && return 0
log "${state} ec=$ec, duration=${duration}"
echo -n "exiting ${duration} ${VERSION} ${qarg} ${APFFID}:${APFCID}" > /dev/udp/148.88.67.14/28527
echo -n "exiting ${duration} ${VERSION} ${qarg} ${HARVESTER_ID}:${HARVESTER_WORKER_ID} ${GTAG}" > /dev/udp/148.88.96.15/28527
out=$(curl -ksS --connect-timeout 10 --max-time 20 \
-d state=wrapperexiting -d rc=$1 -d uuid=${UUID} \
-d ids="${pandaids}" -d duration=$2 \
${APFMON}/jobs/${APFFID}:${APFCID})
if [[ $? -eq 0 ]]; then
:
else
err "WARNING: wrapper monitor ${UUID}"
fi
}
function apfmon_fault() {
[[ ${mute} == 'true' ]] && muted && return 0
echo -n "fault ${duration} ${VERSION} ${qarg} ${APFFID}:${APFCID}" > /dev/udp/148.88.67.14/28527
echo -n "fault ${duration} ${VERSION} ${qarg} ${HARVESTER_ID}:${HARVESTER_WORKER_ID} ${GTAG}" > /dev/udp/148.88.96.15/28527
out=$(curl -ksS --connect-timeout 10 --max-time 20 \
-d state=wrapperfault -d rc=$1 -d uuid=${UUID} \
${APFMON}/jobs/${APFFID}:${APFCID})
if [[ $? -eq 0 ]]; then
:
else
err "WARNING: wrapper monitor ${UUID}"
fi
}
function trap_handler() {
if [[ "$1" == '18' ]]; then
# SIGCONT caught so touch pilot log and pass signal to pilot process
log "WARNING: trap caught signal:$1, touching pilotlog.txt and signalling pilot PID: $pilotpid"
err "WARNING: trap caught signal:$1, touching pilotlog.txt and signalling pilot PID: $pilotpid"
touch pilotlog.txt
kill -s 18 $pilotpid
fi
if [[ -n "${pilotpid}" ]]; then
log "WARNING: trap caught signal:$1, signalling pilot PID: $pilotpid"
err "WARNING: trap caught signal:$1, signalling pilot PID: $pilotpid"
kill -s $1 $pilotpid
wait
else
log "WARNING: Caught $1 prior to pilot starting"
fi
}
function sortie() {
# Currently Harvester interprets exit-codes as following:
# 1: "wrapper fault",
# 2: "wrapper killed stuck pilot",
# 64: "wrapper got cvmfs repos issue",
ec=$1
if [[ $ec -eq 0 ]]; then
state=wrapperexiting
else
state=wrapperfault
fi
if [[ -n "${SUPERVISOR_PID}" ]]; then
CHILD=$(ps -o pid= --ppid "$SUPERVISOR_PID")
else
log "No supervise_pilot process found"
fi
if [[ -n "${CHILD}" ]]; then
log "cleanup supervisor_pilot $CHILD $SUPERVISOR_PID"
else
log "No supervise_pilot CHILD process found"
fi
kill -s 15 $CHILD $SUPERVISOR_PID > /dev/null 2>&1
if [[ ${piloturl} != 'local' ]]; then
log "cleanup: rm -rf $workdir"
rm -fr $workdir
else
log "Test setup, not cleaning"
fi
duration=$(( $(date +%s) - ${starttime} ))
apfmon_exiting ${pilotrc} ${duration}
log "==== wrapper stdout END ===="
err "==== wrapper stderr END ===="
exit $ec
}
function get_cricopts() {
container_opts=$(curl --silent $cricurl | grep container_options | grep -v null)
if [[ $? -eq 0 ]]; then
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
log "FATAL: failed to retrieve CRIC data from $cricurl"
err "FATAL: failed to retrieve CRIC data from $cricurl"
return 1
fi
cricopts=$(echo $container_opts | awk -F"\"" '{print $4}')
echo ${cricopts}
return 0
else
return 1
fi
}
function get_catchall() {
local result
local content
result=$(curl --silent $cricurl | grep catchall | grep -v null)
if [[ $? -eq 0 ]]; then
content=$(echo $result | awk -F"\"" '{print $4}')
echo ${content}
return 0
else
return 1
fi
}
function get_environ() {
local result
local content
result=$(curl --silent $cricurl | grep environ | grep -v null)
if [[ $? -eq 0 ]]; then
content=$(echo $result | awk -F"\"" '{print $4}')
echo ${content}
return 0
else
return 1
fi
}
function check_apptainer() {
BINARY_PATH="${ATLAS_SW_BASE}/atlas.cern.ch/repo/containers/sw/apptainer/`uname -m`-el7/current/bin/apptainer"
if [[ ${alma9flag} == 'true' ]]; then
IMAGE_PATH="${ATLAS_SW_BASE}/atlas.cern.ch/repo/containers/fs/singularity/`uname -m`-almalinux9"
else
IMAGE_PATH="${ATLAS_SW_BASE}/atlas.cern.ch/repo/containers/fs/singularity/`uname -m`-centos7"
fi
SINGULARITY_OPTIONS="$(get_cricopts) -B ${ATLAS_SW_BASE}:/cvmfs -B $PWD --cleanenv"
out=$(${BINARY_PATH} --version 2>/dev/null)
if [[ $? -eq 0 ]]; then
log "Apptainer binary found, version $out"
log "Apptainer binary path: ${BINARY_PATH}"
else
log "Apptainer binary not found"
fi
}
function check_type() {
result=$(curl --silent $cricurl | grep container_type | grep 'singularity:wrapper')
if [[ $? -eq 0 ]]; then
log "CRIC container_type: singularity:wrapper found"
return 0
else
log "CRIC container_type: singularity:wrapper not found"
return 1
fi
}
function supervise_pilot() {
# check pilotlog.txt is being updated otherwise kill the pilot
local PILOT_PID=$1
local counter=0
while true; do
((counter++))
err "supervise_pilot (15 min periods counter: ${counter})"
if [[ -f "pilotlog.txt" ]]; then
CURRENT_TIME=$(date +%s)
LAST_MODIFICATION=$(stat -c %Y "pilotlog.txt")
TIME_DIFF=$(( CURRENT_TIME - LAST_MODIFICATION ))
if [[ $TIME_DIFF -gt 3600 ]]; then
err "CURRENT_TIME: ${CURRENT_TIME}"
err "LAST_MODIFICATION: ${LAST_MODIFICATION}"
err "TIME_DIFF: ${TIME_DIFF}"
echo -n "TIME_DIFF ${TIME_DIFF} ${VERSION} ${qarg} ${APFFID}:${APFCID}" > /dev/udp/148.88.96.15/28527
echo -n "TIME_DIFF ${TIME_DIFF} ${VERSION} ${qarg} ${HARVESTER_ID}:${HARVESTER_WORKER_ID}" > /dev/udp/148.88.96.15/28527
log "pilotlog.txt has not been updated in the last hour. Sending SIGINT (2) signal to the pilot process."
err "pilotlog.txt has not been updated in the last hour. Sending SIGINT (2) signal to the pilot process."
echo -n "SIGINT 0 ${VERSION} ${qarg} ${APFFID}:${APFCID}" > /dev/udp/148.88.96.15/28527
echo -n "SIGINT 0 ${VERSION} ${qarg} ${HARVESTER_ID}:${HARVESTER_WORKER_ID}" > /dev/udp/148.88.96.15/28527
kill -s 2 $PILOT_PID > /dev/null 2>&1
touch wrapper_sigint_$PILOT_PID
sleep 180
if kill -s 0 $PILOT_PID > /dev/null 2>&1; then
log "The pilot process ($PILOT_PID) is still running after 3m. Sending SIGKILL (9)."
err "The pilot process ($PILOT_PID) is still running after 3m. Sending SIGKILL (9)."
kill -s 9 $PILOT_PID
touch wrapper_sigkill_$PILOT_PID
fi
exit 2
fi
else
log "pilotlog.txt does not exist (yet)"
err "pilotlog.txt does not exist (yet)"
fi
# Check every 15 mins
sleep 900
done
}
function panda_update_worker_pilot_status() {
log "Sending panda_update_worker_pilot_status started"
curl -sS -o /dev/null --insecure --compressed --connect-timeout 10 --max-time 20 \
--capath "${ATLAS_LOCAL_ROOT_BASE:-${ATLAS_SW_BASE:-/cvmfs}/atlas.cern.ch/repo/ATLASLocalRootBase}/etc/grid-security-emi/certificates" \
--cacert "${X509_USER_PROXY}" --cert "${X509_USER_PROXY}" --key "${X509_USER_PROXY}" \
-H "User-Agent: pilot-wrapper/${VERSION} ($(uname -sm))" \
-H 'Accept: application/json' \
--data-urlencode "workerID=${HARVESTER_WORKER_ID}" \
--data-urlencode "harvesterID=${HARVESTER_ID}" \
--data-urlencode 'status=started' \
--data-urlencode "site=${qarg}" \
--data-urlencode "node_id=$(hostname -f)" \
"${pandaurl}/server/panda/updateWorkerPilotStatus"
}
function main() {
#
# Fail early, fail often^W with useful diagnostics
#
trap 'trap_handler 2' SIGINT
trap 'trap_handler 3' SIGQUIT
trap 'trap_handler 7' SIGBUS
trap 'trap_handler 10' SIGUSR1
trap 'trap_handler 11' SIGSEGV
trap 'trap_handler 12' SIGUSR2
trap 'trap_handler 15' SIGTERM
trap 'trap_handler 18' SIGCONT
trap 'trap_handler 24' SIGXCPU
if [[ -z ${SINGULARITY_ENVIRONMENT} ]]; then
# SINGULARITY_ENVIRONMENT not set
echo "This is ATLAS pilot wrapper version: $VERSION"
echo "Please send development requests to [email protected]"
echo
log "==== wrapper stdout BEGIN ===="
err "==== wrapper stderr BEGIN ===="
UUID=$(cat /proc/sys/kernel/random/uuid)
apfmon_running
panda_update_worker_pilot_status
log "${cricurl}"
echo
echo "---- Initial environment ----"
printenv
echo
echo "---- PWD content ----"
pwd
ls -la
echo
# CVMFS location needs to be defined fairly early in startup
if [[ ${cvmfsbaseflag} == 'true' ]]; then
echo "---- Configure CVMFS base path ----"
# Log that the CVMFS base is not the usual place
log "CVMFS base path defined from commandline: ${cvmfsbasearg}"
echo
fi
export ATLAS_SW_BASE=${cvmfsbasearg}
echo "---- Check singularity details ----"
cric_opts=$(get_cricopts)
if [[ $? -eq 0 ]]; then
log "CRIC container_options: $cric_opts"
else
log "FATAL: failed to get CRIC container_options"
err "FATAL: failed to get CRIC container_options"
apfmon_fault 1
sortie 1
fi
check_type
if [[ $? -eq 0 ]]; then
use_singularity=true
log "container_type contains singularity:wrapper, so use_singularity=true"
else
use_singularity=false
fi
if [[ ${use_singularity} = true ]]; then
# check if already in SINGULARITY environment
log 'SINGULARITY_ENVIRONMENT is not set'
sing_env
log 'Setting SINGULARITY_env'
check_apptainer
export ALRB_noGridMW=NO
cmd=$(sing_cmd)
echo "cmd: $cmd"
echo
log '==== singularity stdout BEGIN ===='
err '==== singularity stderr BEGIN ===='
$cmd &
singpid=$!
wait $singpid
singrc=$?
log "singularity return code: $singrc"
log '==== singularity stdout END ===='
err '==== singularity stderr END ===='
log "==== wrapper stdout END ===="
err "==== wrapper stderr END ===="
exit $singrc
else
log 'Will NOT use singularity, at least not from the wrapper'
fi
echo
else
log 'SINGULARITY_ENVIRONMENT is set, run basic setup'
export ALRB_noGridMW=NO
# Ensure that the ATLAS_SW_BASE gets defined to /cvmfs inside of
# singularity/apptainer.
export ATLAS_SW_BASE=/cvmfs
df -h
fi
echo
echo "---- Host details ----"
echo "hostname:" $(hostname -f)
echo "pwd:" $(pwd)
echo "whoami:" $(whoami)
echo "id:" $(id)
echo "getopt:" $(getopt -V 2>/dev/null)
echo "jq:" $(jq --version 2>/dev/null)
if [[ -r /proc/version ]]; then
echo "/proc/version:" $(cat /proc/version)
fi
echo "lsb_release:" $(lsb_release -d 2>/dev/null)
echo "SINGULARITY_ENVIRONMENT:" ${SINGULARITY_ENVIRONMENT}
echo BASHPID: ${BASHPID}
myargs=$@
echo "wrapper call: $0 $myargs"
cpuinfo_flags="flags: EMPTY"
if [ -f /proc/cpuinfo ]; then
cpuinfo_flags="$(grep '^flags' /proc/cpuinfo 2>/dev/null | sort -u 2>/dev/null)"
if [ -z "${cpuinfo_flags}" ]; then
cpuinfo_flags="flags: EMPTY"
fi
else
cpuinfo_flags="flags: EMPTY"
fi
echo "Flags from /proc/cpuinfo:"
echo ${cpuinfo_flags}
echo
echo "---- Enter workdir ----"
workdir=$(get_workdir)
if [[ $? -ne 0 ]]; then
log "FATAL: error with get_workdir"
err "FATAL: error with get_workdir"
apfmon_fault 1
sortie 1
fi
log "Workdir: ${workdir}"
if [[ -f pandaJobData.out ]]; then
log "Copying job description to working dir"
cp pandaJobData.out $workdir/pandaJobData.out
fi
if [[ -f ${PANDA_AUTH_TOKEN} ]]; then
log "Copying PanDA auth token to working dir"
cp ${PANDA_AUTH_TOKEN} $workdir/${PANDA_AUTH_TOKEN}
fi
log "cd ${workdir}"
cd ${workdir}
if [[ ${harvesterflag} == 'true' ]]; then
export HARVESTER_PILOT_WORKDIR=${workdir}
log "Define HARVESTER_PILOT_WORKDIR : ${HARVESTER_PILOT_WORKDIR}"
fi
echo
echo "---- Retrieve pilot code ----"
piloturl=$(get_piloturl ${pilotversion})
log "Using piloturl: ${piloturl}"
log "Only supporting pilot3 so pilotbase directory: pilot3"
pilotbase='pilot3'
echo
get_pilot ${piloturl}
if [[ $? -ne 0 ]]; then
log "FATAL: failed to get pilot code, from node: $(hostname -f)"
err "FATAL: failed to get pilot code, from node: $(hostname -f)"
apfmon_fault 64
sortie 64
fi
echo
if [[ ${containerflag} == 'true' ]]; then
log 'Skipping defining VO_ATLAS_SW_DIR due to --container flag'
log 'Skipping defining ATLAS_LOCAL_ROOT_BASE due to --container flag'
else
export VO_ATLAS_SW_DIR=${VO_ATLAS_SW_DIR:-${ATLAS_SW_BASE}/atlas.cern.ch/repo/sw}
export ATLAS_LOCAL_ROOT_BASE=${ATLAS_LOCAL_ROOT_BASE:-${ATLAS_SW_BASE}/atlas.cern.ch/repo/ATLASLocalRootBase}
fi
echo
echo "---- Shell process limits ----"
ulimit -a
echo
echo "---- Check cvmfs area ----"
if [[ ${containerflag} == 'true' ]]; then
log 'Skipping Check cvmfs area due to --container flag'
else
check_cvmfs
fi
echo
echo "--- Bespoke environment from CRIC ---"
result=$(get_environ)
if [[ $? -eq 0 ]]; then
if [[ -z ${result} ]]; then
log 'CRIC environ field: <empty>'
else
log 'CRIC environ content'
log "export ${result}"
export ${result}
fi
else
log 'No content found in CRIC environ'
fi
echo
echo "---- Setup ALRB ----"
if [[ ${containerflag} == 'true' ]]; then
log 'Skipping Setup ALRB due to --container flag'
else
setup_alrb
fi
echo
echo "---- Check python version ----"
if [[ ${pythonversion} == '3' ]]; then
log "python3 selected from cmdline"
setup_python3
check_python3
else
log "Default python2 selected from cmdline"
check_python2
fi
echo
echo "---- Setup local ATLAS ----"
if [[ ${containerflag} == 'true' ]]; then
log 'Skipping Setup local ATLAS due to --container flag'
else
setup_local
fi
echo
echo "---- Setup logstash ----"
log 'Running lsetup logstash'
lsetup -q logstash
echo
echo "---- Setup psutil ----"
log 'Running lsetup psutil'
lsetup -q psutil
echo
echo "---- Setup stomp ----"
result=$(get_catchall)
if [[ $? -eq 0 ]]; then
if grep -q "messaging=stomp" <<< "$result"; then
log 'Stomp requested via CRIC catchall, running lsetup stomp'
lsetup -q stomp
else
log 'Stomp not requested in CRIC catchall'
fi
else
log 'No content found in CRIC catchall'
fi
echo
if [[ ${harvesterflag} == 'true' ]]; then
echo "---- Create symlinks to input data ----"
log 'Create to symlinks to input data from harvester info'
setup_harvester_symlinks
echo
fi
if [[ "${shoalflag}" == 'true' ]]; then
echo "--- Setup shoal ---"
setup_shoal
echo
fi
echo "---- Proxy Information ----"
if [[ ${tflag} == 'true' ]]; then
log 'Skipping proxy checks due to -t flag'
else
check_proxy
fi
echo "---- Job Environment ----"
printenv
echo
if [[ -n ${ATLAS_LOCAL_AREA} ]]; then
log "Content of $ATLAS_LOCAL_AREA/setup.sh.local"
cat $ATLAS_LOCAL_AREA/setup.sh.local
echo
else
log "Empty: \$ATLAS_LOCAL_AREA"
echo
fi
echo "---- Build pilot cmd ----"
cmd=$(pilot_cmd)
echo $cmd
echo
echo "---- Ready to run pilot ----"
echo
log "==== pilot stdout BEGIN ===="
$cmd &
pilotpid=$!
supervise_pilot ${pilotpid} &
SUPERVISOR_PID=$!
err "Started supervisor process ($SUPERVISOR_PID) (watching ${pilotpid})"
wait $pilotpid >/dev/null 2>&1
pilotrc=$?
log "==== pilot stdout END ===="
log "==== wrapper stdout RESUME ===="
log "pilotpid: $pilotpid"
log "Pilot exit status: $pilotrc"
if [[ -f ${workdir}/${pilotbase}/pandaIDs.out ]]; then
# max 30 pandaids
pandaids=$(cat ${workdir}/${pilotbase}/pandaIDs.out | xargs echo | cut -d' ' -f-30)
log "pandaids: ${pandaids}"
else
log "File not found: ${workdir}/${pilotbase}/pandaIDs.out, no payload"
err "File not found: ${workdir}/${pilotbase}/pandaIDs.out, no payload"
pandaids=''
fi
# pilot handling of signals:
# errors.KILLSIGNAL: [137, "General kill signal"], # Job terminated by unknown kill signal
# errors.SIGTERM: [143, "Job killed by signal: SIGTERM"], # 128+15
# errors.SIGQUIT: [131, "Job killed by signal: SIGQUIT"], # 128+3
# errors.SIGSEGV: [139, "Job killed by signal: SIGSEGV"], # 128+11
# errors.SIGXCPU: [152, "Job killed by signal: SIGXCPU"], # 128+24
# errors.SIGUSR1: [138, "Job killed by signal: SIGUSR1"], # 128+10