comparison util/startup.lua @ 13979:2041c347c178 13.0

util.startup: Inform process manager about failure to reload config Ref https://www.freedesktop.org/software/systemd/man/249/sd_notify.html > Note that a service that sends this notification must also send a > "READY=1" notification when it completed reloading its configuration. However no word on how to handle errors while doing that, such as configuration syntax errors, but communicating this via STATUS= makes some sense. Fixes #1970
author Kim Alvefur <zash@zash.se>
date Mon, 06 Oct 2025 01:22:40 +0200
parents 0c7e11c11968
children d8c001271669 a957cd3ea4eb
comparison
equal deleted inserted replaced
13974:9974b210d620 13979:2041c347c178
345 if level == "parser" then 345 if level == "parser" then
346 log("error", "There was an error parsing the configuration file: %s", err); 346 log("error", "There was an error parsing the configuration file: %s", err);
347 elseif level == "file" then 347 elseif level == "file" then
348 log("error", "Couldn't read the config file when trying to reload: %s", err); 348 log("error", "Couldn't read the config file when trying to reload: %s", err);
349 end 349 end
350 prosody.events.fire_event("config-reload-failed", {
351 filename = prosody.config_file;
352 level = level; error = err;
353 });
350 else 354 else
351 prosody.events.fire_event("config-reloaded", { 355 prosody.events.fire_event("config-reloaded", {
352 filename = prosody.config_file, 356 filename = prosody.config_file,
353 config = config.getconfig(), 357 config = config.getconfig(),
354 }); 358 });
856 prosody.events.add_handler("server-started", function() 860 prosody.events.add_handler("server-started", function()
857 notify_socket:send("READY=1"); 861 notify_socket:send("READY=1");
858 end); 862 end);
859 prosody.events.add_handler("reloading-config", function() 863 prosody.events.add_handler("reloading-config", function()
860 notify_socket:send(string.format("RELOADING=1\nMONOTONIC_USEC=%d", math.floor(time.monotonic() * 1000000))); 864 notify_socket:send(string.format("RELOADING=1\nMONOTONIC_USEC=%d", math.floor(time.monotonic() * 1000000)));
865 end);
866 prosody.events.add_handler("config-reload-failed", function(event)
867 if event and event.level == "parser" then
868 notify_socket:send(string.format("READY=1\nSTATUS=Error parsing configuration file: %s", tostring(event.error)));
869 elseif event and event.level == "file" then
870 notify_socket:send(string.format("READY=1\nSTATUS=Could not read configuration file: %s", tostring(event.error)));
871 else
872 notify_socket:send("READY=1\nSTATUS=Could not read configuration file");
873 end
861 end); 874 end);
862 prosody.events.add_handler("config-reloaded", function() 875 prosody.events.add_handler("config-reloaded", function()
863 notify_socket:send("READY=1"); 876 notify_socket:send("READY=1");
864 end); 877 end);
865 prosody.events.add_handler("server-stopping", function() 878 prosody.events.add_handler("server-stopping", function()