How to make mosquitto broker auto-start on Mac OS (without homebrew)? I understand that using homebrew, a plist file will be provided and a user can use launchctl to install that plist file.

But, I am not using homebrew(nor macport). I built mosquitto binaries directly from mosquitto source distribution and I would like to be able to start mosquitto broker automatically (just like other daemons).
The homebrew mosquitto launch agent looks 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;homebrew.mxcl.mosquitto&lt;/string&gt;
  &lt;key&gt;ProgramArguments&lt;/key&gt;
  &lt;array&gt;
    &lt;string&gt;/usr/local/opt/mosquitto/sbin/mosquitto&lt;/string&gt;
    &lt;string&gt;-c&lt;/string&gt;
    &lt;string&gt;/usr/local/etc/mosquitto/mosquitto.conf&lt;/string&gt;
  &lt;/array&gt;
  &lt;key&gt;RunAtLoad&lt;/key&gt;
  &lt;true/&gt;
  &lt;key&gt;KeepAlive&lt;/key&gt;
  &lt;false/&gt;
  &lt;key&gt;WorkingDirectory&lt;/key&gt;
  &lt;string&gt;/usr/local/var/mosquitto&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;


Depending on your installation directory of mosquitto modify the two path strings in ProgramArguments  and the path of the WorkingDirectory.

Also modify the Label to org.user.mosquitto (to avoid future conflicts with a possíble homebrew mosquitto install) and then save the file as org.user.mosquitto.plist to ~/Library/LaunchAgents/.

Load the agent with launchctl load ~/Library/LaunchAgents/org.user.mosquitto.plist.



Under certain circumstances (the make install options which you didn't specify in your question) it may be necessary to save the plist file to /Library/LaunchAgents (instead of ~/Library/LaunchAgents), modify permissions to root:wheel 644 and start it with: 

sudo launchctl load /Library/LaunchAgents/org.user.mosquitto.plist




Now you can test the installation and ensure the server is running successfully.  Open a new command window and start a listener.

mosquitto_sub -t topic/state


In another window, send a message to the listener.

mosquitto_pub -t topic/state -m "Hello World"