Reputation: 2970
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?
Upvotes: 8
Views: 14549
Reputation: 463
Assuming you have .NET Framework installed, which comes by default in newer versions of Windows, Mosquitto settings can be reloaded through a PowerShell script that publishes a named event. This way you don't need to go deep into the Windows API to notify Mosquitto.
First you have to set your mosquitto.conf
to save the pid in a file by specifying the pid_file
.
Then, you just need to run this PowerShell script:
$mosquittoPid = cat "mosquitto.pid"
$handle = [System.Threading.EventWaitHandle]::new($false, [System.Threading.EventResetMode]::ManualReset, "mosq${mosquittoPid}_reload")
$handle.Set()
$handle.Dispose()
As previously mentioned by @dlanod, this only works on versions 1.5 or higher.
Upvotes: 0
Reputation: 9020
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.
Upvotes: 2
Reputation: 41
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"
Upvotes: 3
Reputation: 195
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
Upvotes: 6
Reputation: 59751
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.
Upvotes: 1