Attempting to run samba with a LaunchAgent - process won't start with system I've installed Samba3 from MacPorts. (following this guide) To run it I execute sudo /opt/local/sbin/smbd -D &amp;&amp; sudo /opt/local/sbin/nmbd -D in a Terminal window and everything works fine.

I've attempted to create a LaunchAgent to run samba with the system, rather than having to invoke it manually. My plist file is called com.samba3.plist and consists of the following:

&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.samba3&lt;/string&gt;
&lt;key&gt;ProgramArguments&lt;/key&gt;
&lt;array&gt;
&lt;string&gt;/opt/local/sbin/smbd&lt;/string&gt;
&lt;string&gt;-D&lt;/string&gt;
&lt;string&gt;&amp;amp;&amp;amp;&lt;/string&gt;
&lt;string&gt;/opt/local/sbin/nmbd&lt;/string&gt;
&lt;string&gt;-D&lt;/string&gt;
&lt;/array&gt;
&lt;key&gt;RunAtLoad&lt;/key&gt;
&lt;true/&gt;
&lt;/dict&gt;
&lt;/plist&gt;


However, on system startup samba is not being run.
I see several things that need fixing:


This should be installed as a LaunchDaemon, not a LaunchAgent.  The difference is that an agent runs inside a user login session, as the user; a daemon runs independent of who is or isn't logged in, and generally runs as root (which you need here).
The ProgramArgument list isn't parsed by a shell, so &amp;&amp; doesn't do what you want -- it's just passed as an argument to smbd.  You really should make two launchd items, one for smbd and one for nmbd.
The -D flag to each program tells it to daemonize, i.e. detach and run in the background; launchd expects the things it launches to stay connected so it can monitor them (and in fact will think a program has quit if it daemonizes).  Remove the -D flags, and use -F instead.


Also, if you have Snow Leopard (installed or available) take a look at the launchd items that start the system's version of smbd and nmbd; they're /System/Library/LaunchDaemons/smbd.plist and .../nmbd.plist.  They contain some additional tricks which you may find useful.  Most notably, nmbd is set to auto-relaunch if the network is up, and smbd is only launched on demand when a connection is received.