What is a neat way to delete a stale amavisd pid_file on first boot after panic or power failure?

Option 1: Reconfigure amavisd

So that its pid file will be erased upon boot. Thus change the default pid file location from /var/amavis/amavisd.pid to a folder that is empty on every boot. For example /private/var/run.

Note: Lion runs amavisd as user _amavisd. To allow user _amavisd to write anything in /private/var/run the _amavisd user needs to be added to group daemon. Otherwise amavis errors out with:

Couldn't open pid file "/private/var/run/amavisd.pid" [Permission denied]

$ sudo dseditgroup -o edit -a _amavisd -t user daemon
$ sudo nano /etc/amavisd.conf
# $pid_file = "$MYHOME/var/amavisd.pid";   # -P
$pid_file = '/private/var/run/amavisd.pid';
$ sudo launchctl unload /System/Library/LaunchDaemons/org.amavis.amavisd.plist;sudo launchctl load /System/Library/LaunchDaemons/org.amavis.amavisd.plist

Option 2: Create a launchd item

That runs on boot (system startup before amavisd is started) executing the command to test that /var/amavis/amavisd.pid exists and then delete it:

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

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