Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The missing documentation for using the mosquitto "snap" package on Ubuntu #931

Open
bootrino opened this issue Aug 23, 2018 · 7 comments
Open

Comments

@bootrino
Copy link

bootrino commented Aug 23, 2018

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:

Using Mosquitto as a "snap" file on Ubuntu

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.

general tip: to list the systemd mosquitto service unit files

general tip: to stop the mosquitto service:

sudo systemctl stop snap.mosquitto.mosquitto.service

general tip: to start the mosquitto service

sudo systemctl start snap.mosquitto.mosquitto.service

general tip: to find out the current status of the mosquitto service

sudo systemctl status snap.mosquitto.mosquitto.service

general tip: to see the mosquitto service log messages:

sudo journalctl -f -u snap.mosquitto.mosquitto.service

mosquitto will not start if your config file has include_dir /etc/mosquitto/conf.d because it cannot find the directory

to do a test message publish, on the same machine as the server:

mosquitto_sub -h localhost -t test
and on the same machine in a different console:
mosquitto_pub -h localhost -t test -m atestmessage

@ralight
Copy link
Contributor

ralight commented Aug 30, 2018

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.

@bootrino
Copy link
Author

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.

@ralight
Copy link
Contributor

ralight commented Aug 31, 2018

That's right, a normal snap package only has access to specific paths, and that doesn't include anything in /etc.

@bootrino
Copy link
Author

Feel free to move this to the documentation.

@Sequenzial
Copy link

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)

@NicFontana
Copy link

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.

@Sequenzial
Copy link

Makes sence!
Thank you for this Information!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants