Skip to content

Commit fa05006

Browse files
authored
Prevent concurrent migverifyarchives cronjobs and resulting interference (#282)
If there are a many or big archives to verify the hourly run may not complete before the next one kicks in and messes with the same verification output file. Add a simple PID file in the `migverifyarchives` cronjob and use it to prevent multiple running instances that would interfere with one another like that.
2 parents a588bdb + 0c700f9 commit fa05006

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

mig/install/migverifyarchives-template.sh.cronjob

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ if [ ! -d "$archivestaging" ]; then
2929
exit 42
3030
fi
3131

32+
pidfile="__MIG_STATE__/mig_system_run/migverifyarchives.pid"
33+
if [ -e "$pidfile" ]; then
34+
RUN_PID=$(/bin/cat $pidfile)
35+
if /bin/pgrep -f migverifyarchives | /bin/grep "${RUN_PID}" ; then
36+
echo "Warning: an existing instance of $0 is already active"
37+
exit 1
38+
fi
39+
fi
40+
echo $$ > $pidfile
41+
3242
# Monthly long range search for pending finalized files, otherwise only look for today
3343
today=$(date +%Y%m%d)
3444
day_of_month=$(date +%d)
@@ -90,4 +100,6 @@ for archivelist in $(/bin/find "$archivestaging" -type f -regex "$marker_pattern
90100
totalfailed=$((totalfailed+verifyfailed))
91101
done
92102

103+
/bin/rm -f $pidfile
104+
93105
exit $totalfailed

tests/fixture/confs-stdlocal/migverifyarchives

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ if [ ! -d "$archivestaging" ]; then
2929
exit 42
3030
fi
3131

32+
pidfile="/home/mig/state/mig_system_run/migverifyarchives.pid"
33+
if [ -e "$pidfile" ]; then
34+
RUN_PID=$(/bin/cat $pidfile)
35+
if /bin/pgrep -f migverifyarchives | /bin/grep "${RUN_PID}" ; then
36+
echo "Warning: an existing instance of $0 is already active"
37+
exit 1
38+
fi
39+
fi
40+
echo $$ > $pidfile
41+
3242
# Monthly long range search for pending finalized files, otherwise only look for today
3343
today=$(date +%Y%m%d)
3444
day_of_month=$(date +%d)
@@ -90,4 +100,6 @@ for archivelist in $(/bin/find "$archivestaging" -type f -regex "$marker_pattern
90100
totalfailed=$((totalfailed+verifyfailed))
91101
done
92102

103+
/bin/rm -f $pidfile
104+
93105
exit $totalfailed

0 commit comments

Comments
 (0)