6

I modified the default org.postfix.master.plist of postfix to run as a daemon, so it can send me e-mail whenever a local user receives a mail.

Default:

<?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.postfix.master</string>
    <key>Program</key>
    <string>/usr/libexec/postfix/master</string>
    <key>ProgramArguments</key>
    <array>
        <string>master</string>
        <string>-e</string>
        <string>60</string>
    </array>
    <key>QueueDirectories</key>
    <array>
        <string>/var/spool/postfix/maildrop</string>
    </array>
    <key>AbandonProcessGroup</key>
    <true/>
</dict>
</plist>

Modified:

<?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>KeepAlive</key>
        <true/>
        <key>Label</key>
        <string>org.postfix.master</string>
        <key>Program</key>
        <string>/usr/libexec/postfix/master</string>
        <key>ProgramArguments</key>
        <array>
                <string>master</string>
        </array>
        <key>QueueDirectories</key>
        <array>
                <string>/var/spool/postfix/maildrop</string>
        </array>
        <key>AbandonProcessGroup</key>
        <true/>
</dict>
</plist>

However this file is under /System/Library/LaunchDaemons/ so I had to disable SIP temporarily to modify the file. I read that after the next OS Update all my changes will be gone because of SIP. What can I do to make this permanent? Can I put my Launch Daemon under /Library/LaunchDaemons as a second one?

6

I haven't had to deal with this "for real" yet, but I think the best solution is to:

  1. Copy the .plist file into /Library/LaunchDaemons.
  2. Rename it (e.g. by adding "local." to the beginning of the filename), and edit its Label value to match. If you don't change this, launchd is likely to get confused between this and the original.
  3. Make whatever other edits you need
  4. Make sure the ownership is set to root:wheel, and permissions to 644.
  5. Deactivate the original item with e.g. sudo launchctl unload -w /System/Library/LaunchDaemons/org.postfix.master.plist (the -w makes this permanent).
  6. Load your customized replacement with e.g. sudo launchctl load /Library/LaunchDaemons/local.org.postfix.master.plist (or just reboot).

BTW, if you do just disable SIP and modify the existing file, it won't necessarily be reverted by an OS update. But it might, and you'd have to check after every update (including security updates, etc), which is a pain.

1
  • Your solution works. Changing the Label value is indeed important. Otherwise the daemon won't start up. Mar 5 '16 at 13:02
0

I had a similar problem, and the above didn't fix it for me. I'm sharing my take away, if ever it can save anyone some time (I struggled for a few hours with it)

Tldr: I had to run my plist as root


In my case, the plist was loading correctly from the Terminal:

sudo launchctl load /Library/LaunchAgents/com.name.of.the.plist

But it didn't after restarting the computer. By the way, you can check if your plist is loaded with the following:

sudo launchctl list | grep "my.plist"

I saw exactly the error with adding logs:

<key>StandardErrorPath</key>
<string>/Users/XXX/err.log</string>
<key>StandardOutPath</key>
<string>/Users/XXX/out.log</string>

It revealed this error message:

sysadminctl[807:9587] sysadminctl should be run as root, or in interactive mode!

I really thought my script was already run as root (because of being in /Library/LaunchAgents/), but it wasn't, and my script was getting a permission issue!

Now, to run the plist as root:

  • Move the plist from /Library/LaunchAgents/ to /Library/LaunchDaemons/
  • Add the UserName key as follow:
<key>UserName</key>
<string>root</string>

In my case it worked well!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .