Mercurial > prosody-modules
annotate mod_persisthosts/mod_persisthosts.lua @ 4688:05725276fac0
mod_bookmarks2: Use same default as mod_pep for max_items
Should fix the issue with max items until the proper "max" can be used,
by following the configured max.
While "max" is already in trunk, it's not easily usable in 0.11.x
This limit and option was added to mod_pep in Prosody rev aefb96a52f5f
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 15 Sep 2021 17:39:37 +0200 |
parents | 366fadb5c6e5 |
children |
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 |