comparison util/startup.lua @ 10411:db2a06b9ff98

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Sat, 16 Nov 2019 16:52:31 +0100
parents e7f5735f19e1
children 19ec384eb782
comparison
equal deleted inserted replaced
10410:659b577f280c 10411:db2a06b9ff98
5 local prosody = { events = require "util.events".new() }; 5 local prosody = { events = require "util.events".new() };
6 local logger = require "util.logger"; 6 local logger = require "util.logger";
7 local log = logger.init("startup"); 7 local log = logger.init("startup");
8 8
9 local config = require "core.configmanager"; 9 local config = require "core.configmanager";
10 local config_warnings;
10 11
11 local dependencies = require "util.dependencies"; 12 local dependencies = require "util.dependencies";
12 13
13 local original_logging_config; 14 local original_logging_config;
14 15
63 print("More help on configuring Prosody can be found at https://prosody.im/doc/configure"); 64 print("More help on configuring Prosody can be found at https://prosody.im/doc/configure");
64 print("Good luck!"); 65 print("Good luck!");
65 print("**************************"); 66 print("**************************");
66 print(""); 67 print("");
67 os.exit(1); 68 os.exit(1);
69 elseif err and #err > 0 then
70 config_warnings = err;
68 end 71 end
69 prosody.config_loaded = true; 72 prosody.config_loaded = true;
70 end 73 end
71 74
72 function startup.check_dependencies() 75 function startup.check_dependencies()
95 loggingmanager.reload_logging(); 98 loggingmanager.reload_logging();
96 prosody.events.fire_event("logging-reloaded"); 99 prosody.events.fire_event("logging-reloaded");
97 end); 100 end);
98 end 101 end
99 102
100 function startup.log_dependency_warnings() 103 function startup.log_startup_warnings()
101 dependencies.log_warnings(); 104 dependencies.log_warnings();
105 if config_warnings then
106 for _, warning in ipairs(config_warnings) do
107 log("warn", "Configuration warning: %s", warning);
108 end
109 end
102 end 110 end
103 111
104 function startup.sanity_check() 112 function startup.sanity_check()
105 for host, host_config in pairs(config.getconfig()) do 113 for host, host_config in pairs(config.getconfig()) do
106 if host ~= "*" 114 if host ~= "*"
218 prosody.paths.data = config.get("*", "data_path") or CFG_DATADIR or "data"; 226 prosody.paths.data = config.get("*", "data_path") or CFG_DATADIR or "data";
219 end 227 end
220 228
221 function startup.setup_plugindir() 229 function startup.setup_plugindir()
222 local custom_plugin_paths = config.get("*", "plugin_paths"); 230 local custom_plugin_paths = config.get("*", "plugin_paths");
231 local path_sep = package.config:sub(3,3);
223 if custom_plugin_paths then 232 if custom_plugin_paths then
224 local path_sep = package.config:sub(3,3);
225 -- path1;path2;path3;defaultpath... 233 -- path1;path2;path3;defaultpath...
226 -- luacheck: ignore 111 234 -- luacheck: ignore 111
227 CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins"); 235 CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins");
228 prosody.paths.plugins = CFG_PLUGINDIR; 236 prosody.paths.plugins = CFG_PLUGINDIR;
229 end 237 end
238 end
239
240 function startup.setup_plugin_install_path()
241 local installer_plugin_path = config.get("*", "installer_plugin_path") or "custom_plugins";
242 local path_sep = package.config:sub(3,3);
243 -- TODO Figure out what this should be relative to, because CWD could be anywhere
244 installer_plugin_path = config.resolve_relative_path(require "lfs".currentdir(), installer_plugin_path);
245 -- TODO Can probably move directory creation to the install command
246 require "lfs".mkdir(installer_plugin_path);
247 require"util.paths".complement_lua_path(installer_plugin_path);
248 -- luacheck: ignore 111
249 CFG_PLUGINDIR = installer_plugin_path..path_sep..(CFG_PLUGINDIR or "plugins");
250 prosody.paths.plugins = CFG_PLUGINDIR;
230 end 251 end
231 252
232 function startup.chdir() 253 function startup.chdir()
233 if prosody.installed then 254 if prosody.installed then
234 local lfs = require "lfs"; 255 local lfs = require "lfs";
248 log("info", "Reloading configuration file"); 269 log("info", "Reloading configuration file");
249 prosody.events.fire_event("reloading-config"); 270 prosody.events.fire_event("reloading-config");
250 local ok, level, err = config.load(prosody.config_file); 271 local ok, level, err = config.load(prosody.config_file);
251 if not ok then 272 if not ok then
252 if level == "parser" then 273 if level == "parser" then
253 log("error", "There was an error parsing the configuration file: %s", tostring(err)); 274 log("error", "There was an error parsing the configuration file: %s", err);
254 elseif level == "file" then 275 elseif level == "file" then
255 log("error", "Couldn't read the config file when trying to reload: %s", tostring(err)); 276 log("error", "Couldn't read the config file when trying to reload: %s", err);
256 end 277 end
257 else 278 else
258 prosody.events.fire_event("config-reloaded", { 279 prosody.events.fire_event("config-reloaded", {
259 filename = prosody.config_file, 280 filename = prosody.config_file,
260 config = config.getconfig(), 281 config = config.getconfig(),
518 startup.init_global_state(); 539 startup.init_global_state();
519 startup.read_config(); 540 startup.read_config();
520 startup.force_console_logging(); 541 startup.force_console_logging();
521 startup.init_logging(); 542 startup.init_logging();
522 startup.setup_plugindir(); 543 startup.setup_plugindir();
544 -- startup.setup_plugin_install_path();
523 startup.setup_datadir(); 545 startup.setup_datadir();
524 startup.chdir(); 546 startup.chdir();
525 startup.read_version(); 547 startup.read_version();
526 startup.switch_user(); 548 startup.switch_user();
527 startup.check_dependencies(); 549 startup.check_dependencies();
528 startup.log_dependency_warnings(); 550 startup.log_startup_warnings();
529 startup.check_unwriteable(); 551 startup.check_unwriteable();
530 startup.load_libraries(); 552 startup.load_libraries();
531 startup.init_http_client(); 553 startup.init_http_client();
532 startup.make_dummy_hosts(); 554 startup.make_dummy_hosts();
533 end 555 end
543 startup.set_function_metatable(); 565 startup.set_function_metatable();
544 startup.check_dependencies(); 566 startup.check_dependencies();
545 startup.init_logging(); 567 startup.init_logging();
546 startup.load_libraries(); 568 startup.load_libraries();
547 startup.setup_plugindir(); 569 startup.setup_plugindir();
570 -- startup.setup_plugin_install_path();
548 startup.setup_datadir(); 571 startup.setup_datadir();
549 startup.chdir(); 572 startup.chdir();
550 startup.add_global_prosody_functions(); 573 startup.add_global_prosody_functions();
551 startup.read_version(); 574 startup.read_version();
552 startup.log_greeting(); 575 startup.log_greeting();
553 startup.log_dependency_warnings(); 576 startup.log_startup_warnings();
554 startup.load_secondary_libraries(); 577 startup.load_secondary_libraries();
555 startup.init_http_client(); 578 startup.init_http_client();
556 startup.init_data_store(); 579 startup.init_data_store();
557 startup.init_global_protection(); 580 startup.init_global_protection();
558 startup.prepare_to_start(); 581 startup.prepare_to_start();