Single Cron-Instance / Mutex

I have to ensure that cron script can only work with one instance at a time. Now I use a simple TempFile and test it on every script. The problem is that the script cannot release these locks upon interruption / failure. I tried others with pcntl_signal () and can catch ctrl + c and kill now, but no errors. Perhaps you have a suggestion for solving a witch for all occasions?

Hi

+3
source share
2 answers

http://bunwich.blogspot.co.uk/2012/08/run-only-single-instance-of-cron-job.html has a good solution:

LOCKFILE=/var/run/moodle/moodlecron.lock
set -e
(
    flock -n 200 
    trap "rm $LOCKFILE" EXIT 
    echo Add your commands here
) 200>$LOCKFILE
+1
source

lockrun, , , cron.

0

All Articles