3 -- Copyright (C) 2008 Matthew Wild
4 -- Copyright (C) 2008 Waqas Hussain
6 -- This program is free software; you can redistribute it and/or
7 -- modify it under the terms of the GNU General Public License
8 -- as published by the Free Software Foundation; either version 2
9 -- of the License, or (at your option) any later version.
11 -- This program is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 -- GNU General Public License for more details.
16 -- You should have received a copy of the GNU General Public License
17 -- along with this program; if not, write to the Free Software
18 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR");
26 CFG_DATADIR=os.getenv("PROSODY_DATADIR");
31 package.path = CFG_SOURCEDIR.."/?.lua;"..package.path
32 package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath
36 if os.getenv("HOME") then
37 CFG_DATADIR = CFG_DATADIR:gsub("^~", os.getenv("HOME"));
41 -- Required to be able to find packages installed with luarocks
42 pcall(require, "luarocks.require")
45 config = require "core.configmanager"
46 log = require "util.logger".init("general");
48 -- Disable log output, needs to read from config
49 -- require "util.logger".setwriter(function () end);
52 -- TODO: Check for other formats when we add support for them
53 -- Use lfs? Make a new conf/ dir?
54 local ok, err = config.load((CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
57 print("**************************");
58 print("Prosody was unable to find the configuration file.");
59 print("We looked for: "..(CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
60 print("A sample config file is included in the Prosody download called prosody.cfg.lua.dist");
61 print("Copy or rename it to prosody.cfg.lua and edit as necessary.");
62 print("More help on configuring Prosody can be found at http://prosody.im/doc/configure");
64 print("**************************");
69 local server = require "net.server"
71 require "util.dependencies"
73 -- Maps connections to sessions --
77 -- Load and initialise core modules --
80 require "core.xmlhandlers"
81 require "core.rostermanager"
82 require "core.eventmanager"
83 require "core.hostmanager"
84 require "core.modulemanager"
85 require "core.usermanager"
86 require "core.sessionmanager"
87 require "core.stanza_router"
90 pcall(require, "remdebug.engine");
91 if remdebug then remdebug.engine.start() end
94 local cl = require "net.connlisteners";
99 ------------------------------------------------------------------------
102 ------------- Begin code without a home ---------------------
104 local data_path = config.get("*", "core", "data_path") or CFG_DATADIR or "data";
105 require "util.datamanager".set_data_path(data_path);
107 ----------- End of out-of-place code --------------
109 eventmanager.fire_event("server-starting");
112 -- setup error handling
113 setmetatable(_G, { __index = function (t, k) error("Attempt to read a non-existent global '"..k.."'", 2); end, __newindex = function (t, k, v) error("Attempt to set a global: "..tostring(k).." = "..tostring(v), 2); end });
115 local global_ssl_ctx = config.get("*", "core", "ssl");
116 if global_ssl_ctx then
117 local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; };
118 setmetatable(global_ssl_ctx, { __index = default_ssl_ctx });
121 -- start listening on sockets
122 local function do_ports(option, listener, default, conntype)
123 local ports = config.get("*", "core", option) or default;
124 --if type(ports) == "number" then ports = {ports} end;
126 if type(ports) ~= "table" then
127 log("error", "core."..option.." is not a table");
129 for _, port in ipairs(ports) do
130 if type(port) ~= "number" then
131 log("error", "Non-numeric "..option..": "..tostring(port));
133 cl.start(listener, { ssl = conntype ~= "tcp" and global_ssl_ctx, port = port, type = conntype });
139 do_ports("c2s_ports", "xmppclient", {5222}, (global_ssl_ctx and "tls") or "tcp");
140 do_ports("s2s_ports", "xmppserver", {5269}, "tcp");
141 do_ports("legacy_ssl_ports", "xmppclient", {}, "ssl");
143 if config.get("*", "core", "console_enabled") then
144 if cl.get("console") then
145 cl.start("console", { interface = config.get("*", "core", "console_interface") or "127.0.0.1" })
147 log("error", "Console is enabled, but the console module appears not to be loaded");
151 eventmanager.fire_event("server-started");