launchd executes plist twice instead of once?
Howdy!
I have cured my learn junk mail problem by adding a file called com.apple.learnjunkmail.plist to /System/Library/LaunchDaemons and loading it with launchctl.
The file includes the following keys:
Label
com.apple.learnjunkmail
ProgramArguments
array
string /etc/mail/spamassassin/learn_junk_mail
/array
LowPriorityIO
true
Nice
1
StartCalendarInterval
Hour
integer 2
Minute
integer 15
Now, I also modified the learn_junk_mail script to delete junkmail and reconstruct the junkmail mailbox, then email me a Success message.
These are the addtions to the end of /etc/mail/spamassassin/learn_junk_mail:
rm /var/spool/imap/user/junkmail/*. [greater ampersand] /dev/null
rm /var/spool/imap/user/notjunkmail/*. [greater ampersand] /dev/null
sudo -u cyrusimap /usr/bin/cyrus/bin/reconstruct -r -f user/junkmail [greater ampersand] /dev/null
sudo -u cyrusimap /usr/bin/cyrus/bin/reconstruct -r -f user/notjunkmail [greater ampersand] /dev/null
su - admin -c [doublequote] echo 'The script learn_junk_mail ran successfully.' | mail -s 'Success' virus-admin@myactualdomain.org [doublequote]
The email message is supposed to show up at about 2:15 am when the script runs. It always does but ****** and here's the question ******, about three days a week I get a duplicate message three seconds early (so that is one sent at 2:14:57 and one sent at 2:15:00).
It's driving me crazy! Is the script really running twice? Is it a launchd bug? Is it a script interruption because of either the LowPriorityIO or the Nice keys in the plist? Or is it something else? Can I stop it from sending two messages?
Three notes:
1. I thought it might happen only following a day that the server (it is primarily a mail server) is rebooted or the mail is started and stopped. That is not the case.
2. I compared the full headers of both pieces of mail and they are identical except for the Message-Id and the three second time differences in times sent and received.
3. There really can't be any other way that this script is actually running except through launchd -- if I unload the plist, I get no email message.
I know this is a small matter but I would surely appreciated some feedback!
Thanks,
Charlie
P.S. Feel free to use my mods -- they seems to work great except for the double mail (and possibly double running of the script).