Comparison

core/hostmanager.lua @ 1975:a9998fac292c

hostmanager: deactivate() now accepts a reason, closes s2s connections as well as disconnecting users, and unloads modules for the host
author Matthew Wild <mwild1@gmail.com>
date Sat, 17 Oct 2009 15:23:50 +0100
parent 1974:cfac07d8428e
child 1980:8fceabd84d74
comparison
equal deleted inserted replaced
1974:cfac07d8428e 1975:a9998fac292c
9 local ssl = ssl 9 local ssl = ssl
10 10
11 local hosts = hosts; 11 local hosts = hosts;
12 local configmanager = require "core.configmanager"; 12 local configmanager = require "core.configmanager";
13 local eventmanager = require "core.eventmanager"; 13 local eventmanager = require "core.eventmanager";
14 local modulemanager = require "core.modulemanager";
14 local events_new = require "util.events".new; 15 local events_new = require "util.events".new;
16
17 if not _G.prosody.incoming_s2s then
18 require "core.s2smanager";
19 end
20 local incoming_s2s = _G.prosody.incoming_s2s;
15 21
16 -- These are the defaults if not overridden in the config 22 -- These are the defaults if not overridden in the config
17 local default_ssl_ctx = { mode = "client", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; }; 23 local default_ssl_ctx = { mode = "client", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; };
18 24
19 local log = require "util.logger".init("hostmanager"); 25 local log = require "util.logger".init("hostmanager");
60 66
61 log((hosts_loaded_once and "info") or "debug", "Activated host: %s", host); 67 log((hosts_loaded_once and "info") or "debug", "Activated host: %s", host);
62 eventmanager.fire_event("host-activated", host, host_config); 68 eventmanager.fire_event("host-activated", host, host_config);
63 end 69 end
64 70
65 function deactivate(host) 71 function deactivate(host, reason)
66 local host_session = hosts[host]; 72 local host_session = hosts[host];
67 log("info", "Deactivating host: %s", host); 73 log("info", "Deactivating host: %s", host);
68 eventmanager.fire_event("host-deactivating", host, host_session); 74 eventmanager.fire_event("host-deactivating", host, host_session);
69 75
76 reason = reason or { condition = "host-gone", text = "This server has stopped serving "..host };
77
70 -- Disconnect local users, s2s connections 78 -- Disconnect local users, s2s connections
71 for user, session_list in pairs(host_session.sessions) do 79 if host_session.sessions then
72 for resource, session in pairs(session_list) do 80 for username, user in pairs(host_session.sessions) do
73 session:close("host-gone"); 81 for resource, session in pairs(user.sessions) do
82 log("debug", "Closing connection for %s@%s/%s", username, host, resource);
83 session:close(reason);
84 end
74 end 85 end
75 end 86 end
76 -- Components? 87 if host_session.s2sout then
77 88 for remotehost, session in pairs(host_session.s2sout) do
89 if session.close then
90 log("debug", "Closing outgoing connection to %s", remotehost);
91 if session.srv_hosts then session.srv_hosts = nil; end
92 session:close(reason);
93 end
94 end
95 end
96 for remote_session in pairs(incoming_s2s) do
97 if remote_session.to_host == host then
98 log("debug", "Closing incoming connection from %s", remote_session.from_host or "<unknown>");
99 remote_session:close(reason);
100 end
101 end
102
103 if host_session.modules then
104 for module in pairs(host_session.modules) do
105 modulemanager.unload(host, module);
106 end
107 end
108
78 hosts[host] = nil; 109 hosts[host] = nil;
79 eventmanager.fire_event("host-deactivated", host); 110 eventmanager.fire_event("host-deactivated", host);
80 log("info", "Deactivated host: %s", host); 111 log("info", "Deactivated host: %s", host);
81 end 112 end
82 113