On Tue, May 29, 2012 at 09:51:54AM +0200, Bret Lambert wrote:
> > Please avoid 15 minutes past the hour ;-)
> 
> sleep $(($RANDOM % 2048)) && /usr/libexec/spamd-setup -d

Tried something like the above, and found it still
fails at peak times, so I am trying something else:

I made a wrapper called ss (spamd sync), to keep
retrying within a diminishing timeframe.

#!/bin/sh
remaining=$1;shift
cmd=$@
lock=/var/run/$(basename $1).lock
[ -f $lock ] || {
  touch $lock
  while [ $remaining -gt 0 ]; do
    seconds=$(($RANDOM % $remaining))
    echo $(date) $seconds >> $lock
    sleep $s
    $cmd && return || remaining=$(($remaining - $seconds))
  done
  rm $lock
}

0 * * * * ss 3600 /usr/libexec/spamd-setup -d

The time overhead of running the command creates a small
possibility for overlapping of cron events, so I created
a lock file.  This also seemed a good place to store the
sleep value(s).

/var/run/spamd-setup.lock

spamd-setup(8) does not say how it behaves when daemonized.
Maybe this is a better option than running from the cron?

.d.d.

Reply via email to