If you are using the latest version of mosquitto on Ubuntu, which is packaged as a "snap", then you'll need to know how to configure it.
Here is the missing documentation:
Without other configuration, mosquitto loads a default configuration file from $SNAP_COMMON/default_config.conf. $SNAP_COMMON is set to /var/snap/mosquitto/common on Ubuntu, I don't know if it is different on other OSs.
If you want to use your own configuration, put it in
$SNAP_COMMON/mosquitto.conf
i.e.
/var/snap/mosquitto/common/mosquitto.conf
This is the only file that will be used for the configuration. You can use include_dir, but it must point to a location inside /var/snap/mosquitto/common/ - try /var/snap/mosquitto/common/conf.d/
If you run the mosquitto manually as a normal user, the configuration will be loaded from $SNAP_USER_COMMON/mosquitto.conf, i.e. /home/<user>/snap/mosquitto/common/mosquitto.conf, but this will change soon so that you can specify any configuration file you want as is the usual mosquitto behaviour. Your configuration file will still need to be inside $SNAP_USER_COMMON.
In all cases, for mosquitto 1.5.1 and earlier, you will need to add user root to your configuration file so that mosquitto does not try to drop privileges to the mosquitto user. Snaps do not support this changing of user, but the mosquitto snap is strictly confined so it poses a minimal risk.
sudo systemctl stop snap.mosquitto.mosquitto.service
sudo systemctl start snap.mosquitto.mosquitto.service
sudo systemctl status snap.mosquitto.mosquitto.service
sudo journalctl -f -u snap.mosquitto.mosquitto.service
mosquitto_sub -h localhost -t test
and on the same machine in a different console:
mosquitto_pub -h localhost -t test -m atestmessage
I agree this is something that needs documenting, there are definitely some quirks to it. I've edited your comment to clear up some of the points, I hope that is alright.
Is /etc no longerused with snap files? It's pretty annoying if snaps change /etc it's a reasonable assumption that config is in /etc for pretty much anything.
That's right, a normal snap package only has access to specific paths, and that doesn't include anything in /etc.
Feel free to move this to the documentation.
Does anyone know how to clean the db? On normal installation I see a mosquitto.db that can be deleted while the service is down. But on Snapinstall there is no mosquitto.db (or I cannot find it)
Does anyone know how to clean the db? On normal installation I see a mosquitto.db that can be deleted while the service is down. But on Snapinstall there is no mosquitto.db (or I cannot find it)
As stated in the configuration man page (https://mosquitto.org/man/mosquitto-conf-5.html) the persistence is off by default, so the data are stored in memory.
persistence [ true | false ]
If true, connection, subscription and message data will be written to the disk in mosquitto.db at the location dictated by persistence_location. When mosquitto is restarted, it will reload the information stored in mosquitto.db. The data will be written to disk when mosquitto closes and also at periodic intervals as defined by autosave_interval. Writing of the persistence database may also be forced by sending mosquitto the SIGUSR1 signal. If false, the data will be stored in memory only. Defaults to false.
Makes sence!
Thank you for this Information!
Most helpful comment
I agree this is something that needs documenting, there are definitely some quirks to it. I've edited your comment to clear up some of the points, I hope that is alright.