3 -- Copyright (C) 2008-2009 Matthew Wild
4 -- Copyright (C) 2008-2009 Waqas Hussain
6 -- This project is MIT/X11 licensed. Please see the
7 -- COPYING file in the source package for more information.
13 CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR");
15 CFG_DATADIR=os.getenv("PROSODY_DATADIR");
20 package.path = CFG_SOURCEDIR.."/?.lua;"..package.path
21 package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath
25 if os.getenv("HOME") then
26 CFG_DATADIR = CFG_DATADIR:gsub("^~", os.getenv("HOME"));
30 -- Required to be able to find packages installed with luarocks
31 pcall(require, "luarocks.require")
34 config = require "core.configmanager"
35 log = require "util.logger".init("general");
37 -- Disable log output, needs to read from config
38 -- require "util.logger".setwriter(function () end);
41 -- TODO: Check for other formats when we add support for them
42 -- Use lfs? Make a new conf/ dir?
43 local ok, level, err = config.load((CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
46 print("**************************");
47 if level == "parser" then
48 print("A problem occured while reading the config file "..(CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
49 local err_line, err_message = tostring(err):match("%[string .-%]:(%d*): (.*)");
50 print("Error"..(err_line and (" on line "..err_line) or "")..": "..(err_message or tostring(err)));
52 elseif level == "file" then
53 print("Prosody was unable to find the configuration file.");
54 print("We looked for: "..(CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
55 print("A sample config file is included in the Prosody download called prosody.cfg.lua.dist");
56 print("Copy or rename it to prosody.cfg.lua and edit as necessary.");
58 print("More help on configuring Prosody can be found at http://prosody.im/doc/configure");
60 print("**************************");
66 require "util.dependencies"
68 local server = require "net.server"
71 -- Maps connections to sessions --
75 -- Load and initialise core modules --
78 require "core.xmlhandlers"
79 require "core.rostermanager"
80 require "core.eventmanager"
81 require "core.hostmanager"
82 require "core.modulemanager"
83 require "core.usermanager"
84 require "core.sessionmanager"
85 require "core.stanza_router"
88 pcall(require, "remdebug.engine");
89 if remdebug then remdebug.engine.start() end
92 local cl = require "net.connlisteners";
97 ------------------------------------------------------------------------
100 ------------- Begin code without a home ---------------------
102 local data_path = config.get("*", "core", "data_path") or CFG_DATADIR or "data";
103 require "util.datamanager".set_data_path(data_path);
105 ----------- End of out-of-place code --------------
107 eventmanager.fire_event("server-starting");
110 -- setup error handling
111 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 });
113 local global_ssl_ctx = config.get("*", "core", "ssl");
114 if global_ssl_ctx then
115 local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; };
116 setmetatable(global_ssl_ctx, { __index = default_ssl_ctx });
119 -- start listening on sockets
120 local function do_ports(option, listener, default, conntype)
121 local ports = config.get("*", "core", option) or default;
122 --if type(ports) == "number" then ports = {ports} end;
124 if type(ports) ~= "table" then
125 log("error", "core."..option.." is not a table");
127 for _, port in ipairs(ports) do
128 if type(port) ~= "number" then
129 log("error", "Non-numeric "..option..": "..tostring(port));
131 cl.start(listener, { ssl = conntype ~= "tcp" and global_ssl_ctx, port = port, type = conntype });
137 do_ports("c2s_ports", "xmppclient", {5222}, (global_ssl_ctx and "tls") or "tcp");
138 do_ports("s2s_ports", "xmppserver", {5269}, "tcp");
139 do_ports("legacy_ssl_ports", "xmppclient", {}, "ssl");
141 if config.get("*", "core", "console_enabled") then
142 if cl.get("console") then
143 cl.start("console", { interface = config.get("*", "core", "console_interface") or "127.0.0.1" })
145 log("error", "Console is enabled, but the console module appears not to be loaded");
149 eventmanager.fire_event("server-started");