procmail
[Top] [All Lists]

Re: Alternative to a global lockfile...

1997-11-05 12:54:57
Lars Kellogg-Stedman wrote,

| I have a series of scripts that runs every night through cron to expire
| old messages, sort and pack my mh folders, and then index the whole lot.
| I'd like to prevent procmail from delivering any mail whilst this
| processing is going on.

If you're working on MH folders, locks are not necessary.

| One solution would be a global lockfile, but I imagine this would impact
| performance at other times as well: as I understand it, with a global
| lockfile in place, only one instance of procmail could be active
| (delivering to my account) at any given time.
| 
| I'd like to avoid this, if possible.  I only need to stop procmail while
| the scripts are executing.

A global lockfile would not be too damaging if procmail releases it right
away.  For example, in .procmailrc

  LOCKFILE=whatever
  LOCKFILE

would make procmail wait while the cron job had the lock; however, if another
procmail instantiation had the lock, the wait would be brief, as the procmail
process that had the lock would give it up right away.  For everything in
your .procmailrc after that, use local lockfiles the usual way (or no lock-
files for delivery to MH folders) and two simultaneous procmails won't con-
flict unless they're trying to get the same local lockfile.

You could also limit that to the time of day when the cron job can run, if
you're confident that it will not get delayed very long.  For example, if
it is scheduled for midnight and is sure to finish within a half hour, you
can check for the global lockfile only between midnight and 12:30 AM:

    :0
    * ^^From .+ 00:[012]
    {
     # wait for cleanup job or for other procmails waiting for it
     LOCKFILE=whatever
     # when ready, don't make other procmails wait any more
     LOCKFILE
    }

and the rest of the day procmail needn't worry about the cron job.

But a better idea would be for the cron job to get a lock on each folder as
it works on that folder and then release the lock before moving to the next
folder.  (In other words, the cron job and .procmailrc would both use local
lockfiles.)  It might look something like this:

  #!/bin/sh
  for folder in [list of folders or pattern for folders]
  do
    lockfile $folder.lock
    [whatever you need to do for that folder]
    rm -f $folder.lock
  done

If the loop already ends in an rm -f command, you can just add $folder.lock
to its list of targets.

<Prev in Thread] Current Thread [Next in Thread>