Patch mosquitto configuration on runtime

I have configured some mosquitto options, which cause a mosquitto systemd service to spawn.
However, I need to use the contents of a file in the file system on the target device, and use it’s value as the mosquitto clientid.
The file (on our embedded devices) might look like this:

# cat /sys/firmware/devicetree/base/baseboard-sn
123123123

which should mosquitto to connect with the remote_clientid “bridge-123123123”.

I tried creating a service that sets the hostname (which mosquitto then uses), but this is not viable.

I also attempted to patch the generated mosquitto config, but I am unsure whether that is the right path.

Does anyone have any ideas?

Sounds like you might need to ditch the packaged service, and just generate the config in a pre exec step.

Yes, I thought about that. Unfortunately, the definition for the mosquitto service is quite girthy…

In any case, I now created the mosquitto config file by hand, without using the mosquitto options.
On system activation, this config file is copied to a writable dir, and the device’s serial number is appended as client_id.
Then, I enable mosquitto and rewrite the ExecStart command line, pointing to my patched config file.

Thanks!

1 Like