8

I want to reload the mosquitto password file when it is changed. Is possible to send SIGHUP ("signal hang up") or some equivalent to mosquitto server on windows?

Peter G.
  • 14,786
  • 7
  • 57
  • 75
puko
  • 2,819
  • 4
  • 18
  • 27

4 Answers4

7

It is possible to do so. First you have to set your mosquitto.conf to save the pid in a file by specifying the pid_file.

pid_file your/pid/file

Then you can call

$kill -SIGHUP $(cat your/pid/file).

Or else if you already know the PID of the mosquitoo, then you can do

$kill -SIGHUP PID

This will send sighup signal and reload the pwfile. More info can be found at mosquitto conf

Dulaj
  • 179
  • 2
  • 9
  • As reference for reloaded and not reloaded parameters on `SIGHUP` signal, check this document: https://manpages.debian.org/stretch/mosquitto/mosquitto.conf.5.en.html#GENERAL_OPTIONS – Andre Pastore Feb 11 '19 at 20:02
  • Of course, the pid file will not be reloaded. That is used for store the PID of the process. What we need is to get running PID of the process and reload the required configurations (which will be reload from other config files). – Dulaj Feb 13 '19 at 06:19
  • What we needs to reload is the password_file which will be reloaded at the Reload Signal – Dulaj Feb 13 '19 at 06:23
  • 1
    The question specifically asks for Windows. This is for Linux so does not answer the question. – dlanod Oct 27 '20 at 22:24
3

Since I found this thread looking for an answer on Linux I think this reply is relevant for some.

I think I found a simplified version of dulaj's answer (for Linux). If you look at /etc/init.d/mosquitto (found on Mosquitto v.31) you'll see there is a "reload" option which has adds "--signal HUP" to the start-stop-daemon and it listed as "Reloading network daemon configuration: mosquitto".

So you should be able to run "sudo service mosquitto reload"

begleysm
  • 41
  • 4
2

As of version 1.5 of Mosquitto, you can signal the named event mosq<pid>_reload (the relevant code change).

Sample code:

auto h = OpenEvent(EVENT_MODIFY_STATE, FALSE, "mosq0000_reload");
SetEvent(h);

Example to get the pid in Windows can be found at https://learn.microsoft.com/en-us/windows/win32/psapi/enumerating-all-processes.

dlanod
  • 8,664
  • 8
  • 54
  • 96
1

I don't think you can, but you could use the mosquitto-auth-plugin which allows you to keep the ACL in a database that you can update while mosquitto is running.

This lets you a range of different database backends and you can add, remove, change ACL and users on the fly.

hardillb
  • 54,545
  • 11
  • 67
  • 105
  • thanks for your answer, but in this SO thread http://stackoverflow.com/questions/31808612/make-mosquitto-auth-plug-on-windows @jpmens says "No, you cannot use the plugin on your Mosquitto broker on Windows " – puko Aug 24 '16 at 16:15
  • Doh, forgot about that. I'm sure he will accept pull requests to get it to build on windows – hardillb Aug 24 '16 at 16:29