Running net/mosquitto on FreeBSD as non-root and with a different pidfile

net/mosquitto is an open source (BSD licensed) message broker that implements
the MQ Telemetry Transport (MQTT) protocol. I use it for event notification.

Related posts:

In this post:

  • FreeBSD 13
  • mosquitto 2.0.10

My configuration

Here is what I have in my /etc/rc.conf related to mosquitto:

$ grep mosq /etc/rc.conf
mosquitto_enable="YES"
mosquitto_user="mosquitto"
mosquitto_pidfile="/var/run/mosquitto/mosquitto.pid"

The default value for mosquitto_pidfile is /var/run/mosquitto.pid.

The default user is nobody.

I don’t like either default value. I especially don’t like things running as nobody.

The user

This is the user I use. The exact user id (UID) does not matter. I just let the system decide.

$ grep mosq /etc/passwd 
mosquitto:*:10003:10003:mosquitto daemon:/nonexistent:/usr/sbin/nologin

The configuration file

This is a minimal file when running with my configuration.

$ cat /usr/local/etc/mosquitto/mosquitto.conf
cafile /usr/local/share/certs/ca-root-nss.crt
log_dest            syslog
pid_file /var/run/mosquitto/mosquitto.pid

Installing

Installing is just:

$ pkg install mosquitto

Starting

If you get this:

[dan@empty:~] $ sudo service mosquitto start
install: /var/run/mosquitto/mosquitto.pid: No such file or directory
/usr/local/etc/rc.d/mosquitto: WARNING: failed precmd routine for mosquitto

Then you are probably running as non-root and need to pre-create the new PID directory:

$ sudo mkdir /var/run/mosquitto
$ sudo chown mosquitto:mosquitto /var/run/mosquitto
$ ls -ld /var/run/mosquitto
drwxr-xr-x  2 mosquitto  mosquitto  2 Aug 27 22:27 /var/run/mosquitto

Then it works:

$ sudo service mosquitto start
$ ps auwwx | grep mosq
mosquitto 41344  0.0  0.0 39936 21500  -  SsJ  22:28   0:00.01 /usr/local/sbin/mosquitto -c /usr/local/etc/mosquitto/mosquitto.conf -d
dan       41355  0.0  0.0 12868  2428  1  S+J  22:29   0:00.00 grep mosq

Hope that helps.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Comment

Scroll to Top