What is a neat way to delete a stale amavisd pid_file on first boot after panic or power failure? Lion Mail Server component postfix/smtp 100% reproducible blocks inbound smtp mail delivery on first boot after a panic or power failure.

Error messages from mail.log are like:

postfix/smtp[45785]: connect to 127.0.0.1[127.0.0.1]:10024: Connection refused
postfix/smtp[45785]: 2F7131F9A97: to=&lt;user@host.tld&gt;, relay=none, delay=76041, delays=76040/0.36/0.05/0, dsn=4.4.1, status=deferred (connect to 127.0.0.1[127.0.0.1]:10024: Connection refused)
postfix/error[45790]: 550D61F9A99: to=&lt;user@host.tld&gt;, relay=none, delay=76040, delays=76040/0.39/0/0, dsn=4.4.1, status=deferred (delivery temporarily suspended: connect to 127.0.0.1[127.0.0.1]:10024: Connection refused)
postfix/postscreen[45872]: NOQUEUE: reject: RCPT from [100.200.100.159]:65392: 450 4.3.2 Service currently unavailable; from=&lt;user2@host2.tld&gt;, to=&lt;user@host.tld&gt;, proto=ESMTP, helo=&lt;host.domain.tld&gt;
/usr/libexec/postfix/greylist.pl[45885]: Temporary message rejection to: &lt;user@host.tld&gt; from: &lt;user2@host2.tld&gt; sent from: [100.200.100.159] for: 60 seconds due to greylisting
postfix/smtpd[45879]: NOQUEUE: reject: RCPT from host.domain.tld[100.200.100.159]: 450 4.7.1 &lt;user@host.tld&gt;: Recipient address rejected: Service is unavailable; from=&lt;user2@domain2.tld&gt; to=&lt;user@domain.tld&gt; proto=ESMTP helo=&lt;host.domain.tld&gt;


The issue seems to be related to the amavis content filter due to the connection to port number 10024 and amavisd being configured on that port. Amavis.log: 

/usr/bin/amavisd[236]: (!)Net::Server: 2012/07/25-13:38:49 Pid_file already exists for running process (88)... aborting\n\n  at line 277 in file /System/Library/Perl/Extras/5.12/Net/Server.pm
...
/usr/bin/amavisd[236]: Net::Server: 2012/07/25-13:38:49 Server closing!
...repeating roughly every 10 seconds...


The workaround is to reboot the machine, after the second boot the inbound smtp mail delivery is no longer stuck.

The issue seems to be related to https://serverfault.com/questions/138690/amavisd-net-server-pid-file-already-exists-after-system-crash-and-startup

How to permanently fix Apple Mail Server to accept smtp inbound messages on first boot, by removing the left over amavis pid_file from the previous unclean shutdown?
Create a launchd item that runs on boot (system startup before amavisd is started) executing the command to test that /private/var/run/amavisd.pid exists and then delete it:

if test -f /private/var/run/amavisd.pid; then rm /private/var/run/amavisd.pid




&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd &gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;amavisd_delete_pid&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;if&lt;/string&gt;
        &lt;string&gt;test&lt;/string&gt;
        &lt;string&gt;-f&lt;/string&gt;
        &lt;string&gt;/private/var/run/amavisd.pid;&lt;/string&gt;
        &lt;string&gt;then&lt;/string&gt;
        &lt;string&gt;rm&lt;/string&gt;
        &lt;string&gt;/private/var/run/amavisd.pid&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;Nice&lt;/key&gt;
    &lt;integer&gt;10&lt;/integer&gt;
    &lt;key&gt;KeepAlive&lt;/key&gt;
    &lt;false/&gt;
    &lt;key&gt;AbandonProcessGroup&lt;/key&gt;
    &lt;true/&gt;
&lt;/dict&gt;
&lt;/plist&gt;