Software /
code /
prosody
Annotate
core/hostmanager.lua @ 1244:3df7417225fe
stanza_router: Changed to use the prosody.events object directly, rather than through eventmanager2
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 31 May 2009 00:43:24 +0500 |
parent | 1188:fa48e69c4786 |
child | 1467:fc420e9585c2 |
rev | line source |
---|---|
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local hosts = hosts; |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local configmanager = require "core.configmanager"; |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local eventmanager = require "core.eventmanager"; |
1188 | 5 local events_new = require "util.events".new; |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
575
428c951d0a33
Log in hostmanager when a vhost is activated/deactivated
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
7 local log = require "util.logger".init("hostmanager"); |
428c951d0a33
Log in hostmanager when a vhost is activated/deactivated
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
8 |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local pairs = pairs; |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 module "hostmanager" |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 |
1095
cad4205f4925
hostmanager: Reduce log output at startup to 'debug'
Matthew Wild <mwild1@gmail.com>
parents:
749
diff
changeset
|
13 local hosts_loaded_once; |
cad4205f4925
hostmanager: Reduce log output at startup to 'debug'
Matthew Wild <mwild1@gmail.com>
parents:
749
diff
changeset
|
14 |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local function load_enabled_hosts(config) |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local defined_hosts = config or configmanager.getconfig(); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 for host, host_config in pairs(defined_hosts) do |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 if host ~= "*" and (host_config.core.enabled == nil or host_config.core.enabled) then |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 activate(host, host_config); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 end |
749
1359492f45d7
hostmanager: Fire event when all hosts are loaded from config
Matthew Wild <mwild1@gmail.com>
parents:
575
diff
changeset
|
23 eventmanager.fire_event("hosts-activated", defined_hosts); |
1095
cad4205f4925
hostmanager: Reduce log output at startup to 'debug'
Matthew Wild <mwild1@gmail.com>
parents:
749
diff
changeset
|
24 hosts_loaded_once = true; |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 eventmanager.add_event_hook("server-starting", load_enabled_hosts); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 function activate(host, host_config) |
1188 | 30 hosts[host] = {type = "local", connected = true, sessions = {}, host = host, s2sout = {}, events = events_new() }; |
1095
cad4205f4925
hostmanager: Reduce log output at startup to 'debug'
Matthew Wild <mwild1@gmail.com>
parents:
749
diff
changeset
|
31 log((hosts_loaded_once and "info") or "debug", "Activated host: %s", host); |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 eventmanager.fire_event("host-activated", host, host_config); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 function deactivate(host) |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 local host_session = hosts[host]; |
575
428c951d0a33
Log in hostmanager when a vhost is activated/deactivated
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
37 log("info", "Deactivating host: %s", host); |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 eventmanager.fire_event("host-deactivating", host, host_session); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 -- Disconnect local users, s2s connections |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 for user, session_list in pairs(host_session.sessions) do |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 for resource, session in pairs(session_list) do |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 session:close("host-gone"); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 -- Components? |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 hosts[host] = nil; |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 eventmanager.fire_event("host-deactivated", host); |
575
428c951d0a33
Log in hostmanager when a vhost is activated/deactivated
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
50 log("info", "Deactivated host: %s", host); |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 function getconfig(name) |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 |