I have to ensure that a cron script can 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With