Software /
code /
prosody
Annotate
plugins/mod_debug_reset.lua @ 13226:ac44bb7b7064
mod_muc: Use enum option method for 'muc_room_default_presence_broadcast'
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 18 Jul 2023 12:32:41 +0200 |
parent | 13029:8ad432953300 |
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 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 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
|
11 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
|
12 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
|
13 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
|
14 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
|
15 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 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
|
17 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
|
18 hostmanager.deactivate(host); |
13028
b2e6a175537d
mod_debug_reset: Don't delay operations until next tick
Matthew Wild <mwild1@gmail.com>
parents:
12977
diff
changeset
|
19 hostmanager.activate(host); |
b2e6a175537d
mod_debug_reset: Don't delay operations until next tick
Matthew Wild <mwild1@gmail.com>
parents:
12977
diff
changeset
|
20 module:log("info", "Reset complete"); |
b2e6a175537d
mod_debug_reset: Don't delay operations until next tick
Matthew Wild <mwild1@gmail.com>
parents:
12977
diff
changeset
|
21 module:fire_event("server-reset"); |
12968
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 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
|
26 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
|
27 if next(prosody.full_sessions) == nil then |
13028
b2e6a175537d
mod_debug_reset: Don't delay operations until next tick
Matthew Wild <mwild1@gmail.com>
parents:
12977
diff
changeset
|
28 do_reset(); |
12968
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 end); |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 end |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 |
efdb7f2cd578
mod_debug_reset: New module to "reset" a running server (e.g. for testing)
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 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
|
34 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
|
35 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
|
36 }; |