Single Cron-Instance/Mutex
I have to ensure that a cron script c开发者_开发知识库an only run with a single instance at the same time. Now I use a simple TempFile and check it on every scriptstart. The problem with it is, that the script cannot release these lock on abort/failure. I tried some other with pcntl_signal() and can catch ctrl+c and kill now, but no errors. Maybe you have a suggestion witch solution works for all cases?
Greetings
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
I just came across lockrun, which seems to be a good general solution to the cron overrun problem.
精彩评论