Software /
code /
prosody
Comparison
util/startup.lua @ 12975:d10957394a3c
util: Prefix module imports with prosody namespace
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 17 Mar 2023 16:23:16 +0100 |
parent | 12864:9f9633364044 |
child | 12982:fc0109c59807 |
comparison
equal
deleted
inserted
replaced
12974:ba409c67353b | 12975:d10957394a3c |
---|---|
1 -- Ignore the CFG_* variables | 1 -- Ignore the CFG_* variables |
2 -- luacheck: ignore 113/CFG_CONFIGDIR 113/CFG_SOURCEDIR 113/CFG_DATADIR 113/CFG_PLUGINDIR | 2 -- luacheck: ignore 113/CFG_CONFIGDIR 113/CFG_SOURCEDIR 113/CFG_DATADIR 113/CFG_PLUGINDIR |
3 local startup = {}; | 3 local startup = {}; |
4 | 4 |
5 local prosody = { events = require "util.events".new() }; | 5 local prosody = { events = require "prosody.util.events".new() }; |
6 local logger = require "util.logger"; | 6 local logger = require "prosody.util.logger"; |
7 local log = logger.init("startup"); | 7 local log = logger.init("startup"); |
8 local parse_args = require "util.argparse".parse; | 8 local parse_args = require "prosody.util.argparse".parse; |
9 | 9 |
10 local config = require "core.configmanager"; | 10 local config = require "prosody.core.configmanager"; |
11 local config_warnings; | 11 local config_warnings; |
12 | 12 |
13 local dependencies = require "util.dependencies"; | 13 local dependencies = require "prosody.util.dependencies"; |
14 | 14 |
15 local original_logging_config; | 15 local original_logging_config; |
16 | 16 |
17 local default_gc_params = { | 17 local default_gc_params = { |
18 mode = "incremental"; | 18 mode = "incremental"; |
130 -- luacheck: globals socket server | 130 -- luacheck: globals socket server |
131 | 131 |
132 function startup.load_libraries() | 132 function startup.load_libraries() |
133 -- Load socket framework | 133 -- Load socket framework |
134 -- luacheck: ignore 111/server 111/socket | 134 -- luacheck: ignore 111/server 111/socket |
135 require "util.import" | 135 require "prosody.util.import" |
136 socket = require "socket"; | 136 socket = require "socket"; |
137 server = require "net.server" | 137 server = require "prosody.net.server" |
138 end | 138 end |
139 | 139 |
140 function startup.init_logging() | 140 function startup.init_logging() |
141 -- Initialize logging | 141 -- Initialize logging |
142 local loggingmanager = require "core.loggingmanager" | 142 local loggingmanager = require "prosody.core.loggingmanager" |
143 loggingmanager.reload_logging(); | 143 loggingmanager.reload_logging(); |
144 prosody.events.add_handler("config-reloaded", function () | 144 prosody.events.add_handler("config-reloaded", function () |
145 prosody.events.fire_event("reopen-log-files"); | 145 prosody.events.fire_event("reopen-log-files"); |
146 end); | 146 end); |
147 prosody.events.add_handler("reopen-log-files", function () | 147 prosody.events.add_handler("reopen-log-files", function () |
278 startup.detect_installed(); | 278 startup.detect_installed(); |
279 _G.prosody = prosody; | 279 _G.prosody = prosody; |
280 | 280 |
281 -- COMPAT Lua < 5.3 | 281 -- COMPAT Lua < 5.3 |
282 if not math.type then | 282 if not math.type then |
283 require "util.mathcompat" | 283 require "prosody.util.mathcompat" |
284 end | 284 end |
285 end | 285 end |
286 | 286 |
287 function startup.setup_datadir() | 287 function startup.setup_datadir() |
288 prosody.paths.data = config.get("*", "data_path") or CFG_DATADIR or "data"; | 288 prosody.paths.data = config.get("*", "data_path") or CFG_DATADIR or "data"; |
301 | 301 |
302 function startup.setup_plugin_install_path() | 302 function startup.setup_plugin_install_path() |
303 local installer_plugin_path = config.get("*", "installer_plugin_path") or "custom_plugins"; | 303 local installer_plugin_path = config.get("*", "installer_plugin_path") or "custom_plugins"; |
304 local path_sep = package.config:sub(3,3); | 304 local path_sep = package.config:sub(3,3); |
305 installer_plugin_path = config.resolve_relative_path(CFG_DATADIR or "data", installer_plugin_path); | 305 installer_plugin_path = config.resolve_relative_path(CFG_DATADIR or "data", installer_plugin_path); |
306 require"util.paths".complement_lua_path(installer_plugin_path); | 306 require"prosody.util.paths".complement_lua_path(installer_plugin_path); |
307 -- luacheck: ignore 111 | 307 -- luacheck: ignore 111 |
308 CFG_PLUGINDIR = installer_plugin_path..path_sep..(CFG_PLUGINDIR or "plugins"); | 308 CFG_PLUGINDIR = installer_plugin_path..path_sep..(CFG_PLUGINDIR or "plugins"); |
309 prosody.paths.installer = installer_plugin_path; | 309 prosody.paths.installer = installer_plugin_path; |
310 prosody.paths.plugins = CFG_PLUGINDIR; | 310 prosody.paths.plugins = CFG_PLUGINDIR; |
311 end | 311 end |
363 end | 363 end |
364 end | 364 end |
365 | 365 |
366 function startup.load_secondary_libraries() | 366 function startup.load_secondary_libraries() |
367 --- Load and initialise core modules | 367 --- Load and initialise core modules |
368 require "util.xmppstream" | 368 require "prosody.util.xmppstream" |
369 require "core.stanza_router" | 369 require "prosody.core.stanza_router" |
370 require "core.statsmanager" | 370 require "prosody.core.statsmanager" |
371 require "core.hostmanager" | 371 require "prosody.core.hostmanager" |
372 require "core.portmanager" | 372 require "prosody.core.portmanager" |
373 require "core.modulemanager" | 373 require "prosody.core.modulemanager" |
374 require "core.usermanager" | 374 require "prosody.core.usermanager" |
375 require "core.rostermanager" | 375 require "prosody.core.rostermanager" |
376 require "core.sessionmanager" | 376 require "prosody.core.sessionmanager" |
377 package.loaded['core.componentmanager'] = setmetatable({},{__index=function() | 377 package.loaded['core.componentmanager'] = setmetatable({},{__index=function() |
378 -- COMPAT which version? | 378 -- COMPAT which version? |
379 log("warn", "componentmanager is deprecated: %s", debug.traceback():match("\n[^\n]*\n[ \t]*([^\n]*)")); | 379 log("warn", "componentmanager is deprecated: %s", debug.traceback():match("\n[^\n]*\n[ \t]*([^\n]*)")); |
380 return function() end | 380 return function() end |
381 end}); | 381 end}); |
382 | 382 |
383 require "util.array" | 383 require "prosody.util.array" |
384 require "util.datetime" | 384 require "prosody.util.datetime" |
385 require "util.iterators" | 385 require "prosody.util.iterators" |
386 require "util.timer" | 386 require "prosody.util.timer" |
387 require "util.helpers" | 387 require "prosody.util.helpers" |
388 | 388 |
389 pcall(require, "util.signal") -- Not on Windows | 389 pcall(require, "prosody.util.signal") -- Not on Windows |
390 | 390 |
391 -- Commented to protect us from | 391 -- Commented to protect us from |
392 -- the second kind of people | 392 -- the second kind of people |
393 --[[ | 393 --[[ |
394 pcall(require, "remdebug.engine"); | 394 pcall(require, "remdebug.engine"); |
395 if remdebug then remdebug.engine.start() end | 395 if remdebug then remdebug.engine.start() end |
396 ]] | 396 ]] |
397 | 397 |
398 require "util.stanza" | 398 require "prosody.util.stanza" |
399 require "util.jid" | 399 require "prosody.util.jid" |
400 end | 400 end |
401 | 401 |
402 function startup.init_http_client() | 402 function startup.init_http_client() |
403 local http = require "net.http" | 403 local http = require "prosody.net.http" |
404 local config_ssl = config.get("*", "ssl") or {} | 404 local config_ssl = config.get("*", "ssl") or {} |
405 local https_client = config.get("*", "client_https_ssl") | 405 local https_client = config.get("*", "client_https_ssl") |
406 http.default.options.sslctx = require "core.certmanager".create_context("client_https port 0", "client", | 406 http.default.options.sslctx = require "prosody.core.certmanager".create_context("client_https port 0", "client", |
407 { capath = config_ssl.capath, cafile = config_ssl.cafile, verify = "peer", }, https_client); | 407 { capath = config_ssl.capath, cafile = config_ssl.cafile, verify = "peer", }, https_client); |
408 http.default.options.use_dane = config.get("*", "use_dane") | 408 http.default.options.use_dane = config.get("*", "use_dane") |
409 end | 409 end |
410 | 410 |
411 function startup.init_promise() | 411 function startup.init_promise() |
412 local promise = require "util.promise"; | 412 local promise = require "prosody.util.promise"; |
413 | 413 |
414 local timer = require "util.timer"; | 414 local timer = require "prosody.util.timer"; |
415 promise.set_nexttick(function(f) return timer.add_task(0, f); end); | 415 promise.set_nexttick(function(f) return timer.add_task(0, f); end); |
416 end | 416 end |
417 | 417 |
418 function startup.init_async() | 418 function startup.init_async() |
419 local async = require "util.async"; | 419 local async = require "prosody.util.async"; |
420 | 420 |
421 local timer = require "util.timer"; | 421 local timer = require "prosody.util.timer"; |
422 async.set_nexttick(function(f) return timer.add_task(0, f); end); | 422 async.set_nexttick(function(f) return timer.add_task(0, f); end); |
423 async.set_schedule_function(timer.add_task); | 423 async.set_schedule_function(timer.add_task); |
424 end | 424 end |
425 | 425 |
426 function startup.init_data_store() | 426 function startup.init_data_store() |
427 require "core.storagemanager"; | 427 require "prosody.core.storagemanager"; |
428 end | 428 end |
429 | 429 |
430 function startup.prepare_to_start() | 430 function startup.prepare_to_start() |
431 log("info", "Prosody is using the %s backend for connection handling", server.get_backend()); | 431 log("info", "Prosody is using the %s backend for connection handling", server.get_backend()); |
432 -- Signal to modules that we are ready to start | 432 -- Signal to modules that we are ready to start |
463 version_file:close(); | 463 version_file:close(); |
464 if #prosody.version == 12 and prosody.version:match("^[a-f0-9]+$") then | 464 if #prosody.version == 12 and prosody.version:match("^[a-f0-9]+$") then |
465 prosody.version = "hg:"..prosody.version; | 465 prosody.version = "hg:"..prosody.version; |
466 end | 466 end |
467 else | 467 else |
468 local hg = require"util.mercurial"; | 468 local hg = require"prosody.util.mercurial"; |
469 local hgid = hg.check_id(CFG_SOURCEDIR or "."); | 469 local hgid = hg.check_id(CFG_SOURCEDIR or "."); |
470 if hgid then prosody.version = "hg:" .. hgid; end | 470 if hgid then prosody.version = "hg:" .. hgid; end |
471 end | 471 end |
472 end | 472 end |
473 | 473 |
501 -- NOTE: This function is only used by prosodyctl. | 501 -- NOTE: This function is only used by prosodyctl. |
502 -- The prosody process is built with the assumption that | 502 -- The prosody process is built with the assumption that |
503 -- it is already started as the appropriate user. | 503 -- it is already started as the appropriate user. |
504 | 504 |
505 local want_pposix_version = "0.4.0"; | 505 local want_pposix_version = "0.4.0"; |
506 local have_pposix, pposix = pcall(require, "util.pposix"); | 506 local have_pposix, pposix = pcall(require, "prosody.util.pposix"); |
507 | 507 |
508 if have_pposix and pposix then | 508 if have_pposix and pposix then |
509 if pposix._VERSION ~= want_pposix_version then | 509 if pposix._VERSION ~= want_pposix_version then |
510 print(string.format("Unknown version (%s) of binary pposix module, expected %s", | 510 print(string.format("Unknown version (%s) of binary pposix module, expected %s", |
511 tostring(pposix._VERSION), want_pposix_version)); | 511 tostring(pposix._VERSION), want_pposix_version)); |
597 end | 597 end |
598 end | 598 end |
599 | 599 |
600 function startup.init_gc() | 600 function startup.init_gc() |
601 -- Apply garbage collector settings from the config file | 601 -- Apply garbage collector settings from the config file |
602 local gc = require "util.gc"; | 602 local gc = require "prosody.util.gc"; |
603 local gc_settings = config.get("*", "gc") or { mode = default_gc_params.mode }; | 603 local gc_settings = config.get("*", "gc") or { mode = default_gc_params.mode }; |
604 | 604 |
605 local ok, err = gc.configure(gc_settings, default_gc_params); | 605 local ok, err = gc.configure(gc_settings, default_gc_params); |
606 if not ok then | 606 if not ok then |
607 log("error", "Failed to apply GC configuration: %s", err); | 607 log("error", "Failed to apply GC configuration: %s", err); |
609 end | 609 end |
610 return true; | 610 return true; |
611 end | 611 end |
612 | 612 |
613 function startup.init_errors() | 613 function startup.init_errors() |
614 require "util.error".configure(config.get("*", "error_library") or {}); | 614 require "prosody.util.error".configure(config.get("*", "error_library") or {}); |
615 end | 615 end |
616 | 616 |
617 function startup.make_host(hostname) | 617 function startup.make_host(hostname) |
618 return { | 618 return { |
619 type = "local", | 619 type = "local", |
620 events = prosody.events, | 620 events = prosody.events, |
621 modules = {}, | 621 modules = {}, |
622 sessions = {}, | 622 sessions = {}, |
623 users = require "core.usermanager".new_null_provider(hostname) | 623 users = require "prosody.core.usermanager".new_null_provider(hostname) |
624 }; | 624 }; |
625 end | 625 end |
626 | 626 |
627 function startup.make_dummy_hosts() | 627 function startup.make_dummy_hosts() |
628 -- When running under prosodyctl, we don't want to | 628 -- When running under prosodyctl, we don't want to |