-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun-ed-devtracker-collector
executable file
·52 lines (47 loc) · 1.13 KB
/
run-ed-devtracker-collector
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
#!/bin/bash
#
# Wrapper script to run ed-devtracker-collector.pl and watchdog it in
# case it takes too long.
# The script to be run
SCRIPT="./ed-devtracker-collector.pl"
# The lockfile to check
LOCKFILE="ed-devtracker-collector.lock"
# Maximum time to allow the script to run for, in seconds
MAX_ELAPSED=900 # 15 minutes
cd `dirname $0` || exit 1
# Is there an already running instance?
if [ -f "${LOCKFILE}" ];
then
# echo "Lockfile present"
LSOF=$(lsof "${LOCKFILE}" 2>/dev/null | tail -1)
if [ ! -z "${LSOF}" ];
then
echo "Lockfile has a process attached"
PID=$(echo "${LSOF}" | awk '{print $2}')
if [ ! -z "${PID}" ];
then
ELAPSED=$(ps --no-headers -o etimes -p ${PID})
if [ ! -z "${ELAPSED}" ];
then
if [ "${ELAPSED}" -gt "${MAX_ELAPSED}" ];
then
echo "Elapsed time since start \(${ELAPSED}\) > ${MAX_ELAPSED}"
kill ${PID}
else
echo "Elapsed time only ${ELAPSED}"
exit 0
fi
else
echo "Process disappeared before ps"
fi
else
echo "Process disappeared before lsof"
fi
else
# echo "Nothing currently locking"
:;
fi
else
echo "No lock file found"
fi
exec ${SCRIPT}