annotate mod_persisthosts/mod_persisthosts.lua @ 4203:c4002aae4ad3

mod_s2s_keepalive: Use timestamp as iq @id RFC 6120 implies that the id attribute must be unique within a stream. This should fix problems with remote servers that enforce uniqueness and don't answer duplicated ids. If it doesn't do that, then at least you can get a guesstimate at round-trip time from the difference between the result iq stanza and the timestamp it was logged without having to go look for when it was sent, or needing to keep state.
author Kim Alvefur <zash@zash.se>
date Wed, 14 Oct 2020 18:02:10 +0200
parents 366fadb5c6e5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2446
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- mod_persisthosts
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 module:set_global();
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local set = require"util.set";
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local stat = require"lfs".attributes;
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local resolve_relative_path = require"core.configmanager".resolve_relative_path;
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local vhost_path = module:get_option_string("persisthosts_path", "conf.d");
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local path_pattern = resolve_relative_path(prosody.paths.config, vhost_path) .. "/%s.cfg.lua";
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local original = set.new();
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 original:include(prosody.hosts);
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 module:hook("host-activated", function(host)
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 if not original:contains(host) then
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 local path = path_pattern:format(host);
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 if not stat(path) then
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 local fh, err = io.open(path, "w");
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 if fh then
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 fh:write(("VirtualHost%q\n"):format(host));
2447
366fadb5c6e5 mod_persisthosts: Fire an event to allow other modules a chance to write to the new config file
Kim Alvefur <zash@zash.se>
parents: 2446
diff changeset
21 module:fire_event("host-persisted", { host = host, file = fh });
2446
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 fh:close();
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 module:log("info", "Config file for host '%s' created", host);
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 else
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 module:log("error", "Could not open '%s' for writing: %s", path, err or "duno");
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 end
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 else
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 module:log("debug", "File '%s' existed already", path);
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 end
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 else
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 module:log("debug", "VirtualHost '%s' existed already", host);
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 end
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 end);
c563f4d64302 mod_persisthosts: Module that dynamically creates stub configuration files for dynamically activated hosts
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34