Software /
code /
prosody
Annotate
plugins/mod_debug_reset.lua @ 12968:efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Plan to use this for integration tests.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 23 Mar 2023 14:40:51 +0000 |
child | 12970:d36243e98704 |
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 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local hostmanager = require "core.hostmanager"; |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local modulemanager = require "core.modulemanager"; |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local timer = require "util.timer"; |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 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
|
14 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
|
15 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
|
16 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
|
17 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
|
18 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 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
|
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 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 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
|
31 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
|
32 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
|
33 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
|
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 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 }; |