Launchd won't execute a bindfs command I want to use launchd to run bindfs commands at login, as root. I have a plist in /Library/LaunchAgents/loginsftpjailmount.plist (with chmod 600) and a shell script in /usr/local/bin/loginsftpjailmount.sh.

I should start by saying it works - if I change the bash script to run

mkdir /Users/Me/Desktop/itworks


then it successfully creates the directory "itworks", both on login and by running

sudo launchctl load /Library/launchAgents/loginsftpjailmount.plist


And the folder created is owned by root and I have to type in my password to delete it. When I manually run the bash script from the terminal using sudo, the bindfs command works.

So to summarize - I know the script works. I know the plist works. I know they work together with launchd. But the bindfs command doesn't run! I checked the system log with

sudo grep com.user /var/log/system.log


and it says it exits with error 127 (com.user is part of the label for my plist). I searched online and none of the solutions for error 127 work for me. For reference, two plists I have used are:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//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;com.user.loginitem&lt;/string&gt;
&lt;key&gt;ProgramArguments&lt;/key&gt;
&lt;array&gt;
    &lt;string&gt;bash&lt;/string&gt;
    &lt;string&gt;-c&lt;/string&gt;
    &lt;string&gt;bash -c "bindfs /Volumes/BRIGHTRED/ServedDocuments /sftpjail/Documents"&lt;/string&gt;
&lt;/array&gt;
&lt;key&gt;RunAtLoad&lt;/key&gt;
&lt;true/&gt;





and also

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//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;com.user.loginitem&lt;/string&gt;
        &lt;key&gt;Program&lt;/key&gt;
        &lt;string&gt;/usr/local/bin/loginsftpjailmount.sh&lt;/string&gt;
        &lt;key&gt;RunAtLoad&lt;/key&gt;
        &lt;true/&gt;
    &lt;/dict&gt;
&lt;/plist&gt;
The bindfs process has to be started with root privileges. Launching it as agent would prevent this.

So sudo launchctl unload ... and sudo launchctl remove ... (the subcommand remove removes the agent from the launchd database - the file won't get deleted!) the plist, move the plist to /Library/LaunchDaemons/ and reload it with sudo launchctl load ....

A properly named and composed org.user.bindfs.sftpjail.plist would look like this:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//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;org.user.bindfs.sftpjail&lt;/string&gt;
        &lt;key&gt;ProgramArguments&lt;/key&gt;
        &lt;array&gt;
                &lt;string&gt;/opt/local/bin/bindfs&lt;/string&gt;
                &lt;string&gt;/Volumes/BRIGHTRED/ServedDocuments&lt;/string&gt;
                &lt;string&gt;/sftpjail/Documents&lt;/string&gt;
        &lt;/array&gt;
        &lt;key&gt;RunAtLoad&lt;/key&gt;
        &lt;true/&gt;
        &lt;key&gt;StandardErrorPath&lt;/key&gt;
        &lt;string&gt;/tmp/org.user.bindfs.sftpjail.err&lt;/string&gt;
        &lt;key&gt;StandardOutPath&lt;/key&gt;
        &lt;string&gt;/tmp/org.user.bindfs.sftpjail.out&lt;/string&gt;
        &lt;key&gt;WatchPaths&lt;/key&gt;
        &lt;array&gt;
                &lt;string&gt;/Volumes/BRIGHTRED&lt;/string&gt;
        &lt;/array&gt;
&lt;/dict&gt;
&lt;/plist&gt;


The WatchPath key is often required (it was in my case) to avoid timing problems. You may remove the keys StandardErrorPath/StandardOutPath and its strings after ensuring that everything works properly.