-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathwrapper4cron.sh
executable file
·72 lines (61 loc) · 2.42 KB
/
wrapper4cron.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
#!/bin/sh
# #############################################################################
# Bourne shell script to wrapper the eval_fts.py python script. It acquires
# execution lock and then launches the Python script.
# #############################################################################
EXC_LOCK=""
trap 'exit 1' 1 2 3 15
trap '(/bin/rm -f ${EXC_LOCK}) 1> /dev/null 2>&1' 0
# #############################################################################
# get cmssst/evalFTS_wrapper lock:
# ================================
echo "Acquiring lock for cmssst/evalFTS_wrapper"
if [ ! -d /var/tmp/cmssst ]; then
/bin/rm -f /var/tmp/cmssst 1>/dev/null 2>&1
/bin/mkdir /var/tmp/cmssst 1>/dev/null 2>&1
fi
/bin/ln -s $$ /var/tmp/cmssst/evalFTS_wrapper.lock
if [ $? -ne 0 ]; then
# locking failed, get lock information
LKINFO=`/bin/ls -il /var/tmp/cmssst/evalFTS_wrapper.lock 2>/dev/null`
LKFID=`echo ${LKINFO} | /usr/bin/awk '{print $1; exit}' 2>/dev/null`
LKPID=`echo ${LKINFO} | /usr/bin/awk '{print $NF;exit}' 2>/dev/null`
# check process holding lock is still active
/bin/ps -fp ${LKPID} 1>/dev/null 2>&1
if [ $? -eq 0 ]; then
echo " active process ${LKPID} holds lock, exiting"
exit 1
fi
echo " removing leftover lock: ${LKINFO}"
/usr/bin/find /var/tmp/cmssst -inum ${LKFID} -exec /bin/rm -f {} \;
LKPID=""
LKFID=""
LKINFO=""
#
/bin/ln -s $$ /var/tmp/cmssst/evalFTS_wrapper.lock
if [ $? -ne 0 ]; then
echo " failed to acquire lock, exiting"
exit 1
fi
fi
#
# double check we have the lock
LKPID=`(/bin/ls -l /var/tmp/cmssst/evalFTS_wrapper.lock | /usr/bin/awk '{if($(NF-1)=="->")print $NF;else print "";exit}') 2>/dev/null`
if [ "${LKPID}" != "$$" ]; then
echo " lost lock to process ${LKPID}, exiting"
exit 1
fi
LKPID=""
EXC_LOCK="/var/tmp/cmssst/evalFTS_wrapper.lock"
# #############################################################################
# evaluate FTS link/source/destination/site status and upload JSON to MonIT:
# ==========================================================================
`dirname $0`/eval_fts.py -v
# #############################################################################
# release cmssst/evalFTS_wrapper lock:
# =======================================
echo "Releasing lock for cmssst/evalFTS_wrapper"
/bin/rm ${EXC_LOCK}
EXC_LOCK=""
# #############################################################################
exit 0