2

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).

2

The homebrew mosquitto launch agent looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>homebrew.mxcl.mosquitto</string>
  <key>ProgramArguments</key>
  <array>
    <string>/usr/local/opt/mosquitto/sbin/mosquitto</string>
    <string>-c</string>
    <string>/usr/local/etc/mosquitto/mosquitto.conf</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <false/>
  <key>WorkingDirectory</key>
  <string>/usr/local/var/mosquitto</string>
</dict>
</plist>

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"
  • thank you. One thing not mentioned in your answer is to ensure the WorkingDirectory given in the plist file exists. Another thing is that I used launchctl list | grep mosquitto and check the first field (should be a valid pid) to see if the mosquitto broker is successfully launched. – tdwong.star Mar 15 '17 at 5:31
  • @TzunghsingDavidWong Hmm I didn't state it explicitly but implicitly: "Depending on your installation directory of mosquitto modify the two path strings in [...] the path of the WorkingDirectory." ;-) – klanomath Mar 15 '17 at 5:35
  • my bad... overlooked that point. In my case, I didn't install anything. I simply recovered mosquitto binaries and shared libraries from a time-machine backup and dropped them into my /usr/local. And they just work 8-) – tdwong.star Mar 15 '17 at 5:40

You must log in to answer this question.

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