Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
12967:53b0730093d8 | 12968:efdb7f2cd578 |
---|---|
1 -- This module will "reset" the server when the client connection count drops | |
2 -- to zero. This is somewhere between a reload and a full process restart. | |
3 -- It is useful to ensure isolation between test runs, for example. It may | |
4 -- also be of use for some kinds of manual testing. | |
5 | |
6 module:set_global(); | |
7 | |
8 local hostmanager = require "core.hostmanager"; | |
9 local modulemanager = require "core.modulemanager"; | |
10 | |
11 local timer = require "util.timer"; | |
12 | |
13 local function do_reset() | |
14 module:log("info", "Performing reset..."); | |
15 local hosts = {}; | |
16 for host in pairs(prosody.hosts) do | |
17 table.insert(hosts, host); | |
18 end | |
19 module:fire_event("server-resetting"); | |
20 for _, host in ipairs(hosts) do | |
21 hostmanager.deactivate(host); | |
22 timer.add_task(0, function () | |
23 hostmanager.activate(host); | |
24 module:log("info", "Reset complete"); | |
25 module:fire_event("server-reset"); | |
26 end); | |
27 end | |
28 end | |
29 | |
30 function module.add_host(host_module) | |
31 host_module:hook("resource-unbind", function () | |
32 if next(prosody.full_sessions) == nil then | |
33 timer.add_task(0, do_reset); | |
34 end | |
35 end); | |
36 end | |
37 | |
38 local console_env = module:shared("/*/admin_shell/env"); | |
39 console_env.debug_reset = { | |
40 reset = do_reset; | |
41 }; |