Software /
code /
prosody
Annotate
plugins/mod_debug_reset.lua @ 13014:06453c564141
util.startup: Add prosody.started promise to easily execute code after startup
To avoid a race where server-started fires before the promise function body is
run (on next tick), I moved server-started to fire on the next tick, which
seems sensible anyway.
Errors are logged, I'm not sure if we ought to be doing something more here.
I'm sure we'll find out.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 01 Apr 2023 11:56:38 +0100 |
parent | 12977:74b9e05af71e |
child | 13028:b2e6a175537d |
rev | line source |
---|---|
12968
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- This module will "reset" the server when the client connection count drops |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- to zero. This is somewhere between a reload and a full process restart. |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- It is useful to ensure isolation between test runs, for example. It may |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- also be of use for some kinds of manual testing. |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 module:set_global(); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12970
diff
changeset
|
8 local hostmanager = require "prosody.core.hostmanager"; |
12968
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12970
diff
changeset
|
10 local timer = require "prosody.util.timer"; |
12968
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local function do_reset() |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 module:log("info", "Performing reset..."); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local hosts = {}; |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 for host in pairs(prosody.hosts) do |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 table.insert(hosts, host); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 module:fire_event("server-resetting"); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 for _, host in ipairs(hosts) do |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 hostmanager.deactivate(host); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 timer.add_task(0, function () |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 hostmanager.activate(host); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 module:log("info", "Reset complete"); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 module:fire_event("server-reset"); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 end); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 function module.add_host(host_module) |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 host_module:hook("resource-unbind", function () |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 if next(prosody.full_sessions) == nil then |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 timer.add_task(0, do_reset); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 end); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 local console_env = module:shared("/*/admin_shell/env"); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 console_env.debug_reset = { |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 reset = do_reset; |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 }; |