Annotate

util/startup.lua @ 10601:d8b51833926b

Merge 0.11->trunk
author Matthew Wild <mwild1@gmail.com>
date Sun, 19 Jan 2020 15:39:49 +0000
parent 10599:4f655918fef1
parent 10600:08f2fe5ac30f
child 10604:3b0d9919f361
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8638
f8f45bbbd8ba util.startup: Ignore various globals being read and written as part of startup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8637
diff changeset
1 -- Ignore the CFG_* variables
f8f45bbbd8ba util.startup: Ignore various globals being read and written as part of startup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8637
diff changeset
2 -- luacheck: ignore 113/CFG_CONFIGDIR 113/CFG_SOURCEDIR 113/CFG_DATADIR 113/CFG_PLUGINDIR
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local startup = {};
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local prosody = { events = require "util.events".new() };
8720
dba17a70fd22 util.startup: Initialize prosody.log / _G.log here instead of in loggingmanager to reduce dependencies
Kim Alvefur <zash@zash.se>
parents: 8719
diff changeset
6 local logger = require "util.logger";
dba17a70fd22 util.startup: Initialize prosody.log / _G.log here instead of in loggingmanager to reduce dependencies
Kim Alvefur <zash@zash.se>
parents: 8719
diff changeset
7 local log = logger.init("startup");
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local config = require "core.configmanager";
9877
ded5303e1fde util.startup: Log configuration warnings at startup
Matthew Wild <mwild1@gmail.com>
parents: 9873
diff changeset
10 local config_warnings;
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local dependencies = require "util.dependencies";
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13
8666
57780ba1938f util.startup: Move original_logging_config to a local variable
Matthew Wild <mwild1@gmail.com>
parents: 8665
diff changeset
14 local original_logging_config;
57780ba1938f util.startup: Move original_logging_config to a local variable
Matthew Wild <mwild1@gmail.com>
parents: 8665
diff changeset
15
10596
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
16 local short_params = { D = "daemonize", F = "no-daemonize" };
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
17 local value_params = { config = true };
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
18
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
19 function startup.parse_args()
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
20 local parsed_opts = {};
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
21
10600
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
22 if #arg == 0 then
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
23 return;
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
24 end
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
25 while true do
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
26 local raw_param = arg[1];
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
27 if not raw_param then
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
28 break;
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
29 end
10596
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
30
10600
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
31 local prefix = raw_param:match("^%-%-?");
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
32 if not prefix then
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
33 break;
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
34 elseif prefix == "--" and raw_param == "--" then
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
35 table.remove(arg, 1);
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
36 break;
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
37 end
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
38 local param = table.remove(arg, 1):sub(#prefix+1);
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
39 if #param == 1 then
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
40 param = short_params[param];
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
41 end
10596
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
42
10600
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
43 if not param then
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
44 print("Unknown command-line option: "..tostring(param));
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
45 print("Perhaps you meant to use prosodyctl instead?");
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
46 os.exit(1);
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
47 end
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
48
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
49 local param_k, param_v;
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
50 if value_params[param] then
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
51 param_k, param_v = param, table.remove(arg, 1);
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
52 if not param_v then
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
53 print("Expected a value to follow command-line option: "..raw_param);
10596
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
54 os.exit(1);
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
55 end
10600
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
56 else
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
57 param_k, param_v = param:match("^([^=]+)=(.+)$");
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
58 if not param_k then
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
59 if param:match("^no%-") then
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
60 param_k, param_v = param:sub(4), false;
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
61 else
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
62 param_k, param_v = param, true;
10596
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
63 end
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
64 end
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
65 end
10600
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
66 parsed_opts[param_k] = param_v;
08f2fe5ac30f util.startup: Fix logic to make --config work again
Matthew Wild <mwild1@gmail.com>
parents: 10597
diff changeset
67 print("ARG", param_k, param_v);
10596
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
68 end
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
69 prosody.opts = parsed_opts;
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
70 end
cb107ea49b35 util.startup: Add startup step for parsing command-line options
Matthew Wild <mwild1@gmail.com>
parents: 10390
diff changeset
71
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 function startup.read_config()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 local filenames = {};
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 local filename;
10597
25a3c8134b0a prosody/util.startup: Switch to parse_args() for --root and --config
Matthew Wild <mwild1@gmail.com>
parents: 10596
diff changeset
76 if prosody.opts.config then
25a3c8134b0a prosody/util.startup: Switch to parse_args() for --root and --config
Matthew Wild <mwild1@gmail.com>
parents: 10596
diff changeset
77 table.insert(filenames, prosody.opts.config);
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 if CFG_CONFIGDIR then
10597
25a3c8134b0a prosody/util.startup: Switch to parse_args() for --root and --config
Matthew Wild <mwild1@gmail.com>
parents: 10596
diff changeset
79 table.insert(filenames, CFG_CONFIGDIR.."/"..prosody.opts.config);
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 elseif os.getenv("PROSODY_CONFIG") then -- Passed by prosodyctl
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 table.insert(filenames, os.getenv("PROSODY_CONFIG"));
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 else
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 table.insert(filenames, (CFG_CONFIGDIR or ".").."/prosody.cfg.lua");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 for _,_filename in ipairs(filenames) do
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 filename = _filename;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 local file = io.open(filename);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 if file then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 file:close();
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 prosody.config_file = filename;
10389
dbb8dae58265 util.startup: Update config path (fixes #1430)
Kim Alvefur <zash@zash.se>
parents: 9762
diff changeset
92 prosody.paths.config = filename:match("^(.*)[\\/][^\\/]*$");
dbb8dae58265 util.startup: Update config path (fixes #1430)
Kim Alvefur <zash@zash.se>
parents: 9762
diff changeset
93 CFG_CONFIGDIR = prosody.paths.config; -- luacheck: ignore 111
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 break;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 prosody.config_file = filename
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 local ok, level, err = config.load(filename);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 if not ok then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 print("\n");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 print("**************************");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 if level == "parser" then
8728
41c959c5c84b Fix spelling throughout the codebase [codespell]
Kim Alvefur <zash@zash.se>
parents: 8721
diff changeset
103 print("A problem occurred while reading the config file "..filename);
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 print("");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 local err_line, err_message = tostring(err):match("%[string .-%]:(%d*): (.*)");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 if err:match("chunk has too many syntax levels$") then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 print("An Include statement in a config file is including an already-included");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 print("file and causing an infinite loop. An Include statement in a config file is...");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 else
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 print("Error"..(err_line and (" on line "..err_line) or "")..": "..(err_message or tostring(err)));
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 print("");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 elseif level == "file" then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 print("Prosody was unable to find the configuration file.");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 print("We looked for: "..filename);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 print("A sample config file is included in the Prosody download called prosody.cfg.lua.dist");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 print("Copy or rename it to prosody.cfg.lua and edit as necessary.");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 print("More help on configuring Prosody can be found at https://prosody.im/doc/configure");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 print("Good luck!");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 print("**************************");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 print("");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 os.exit(1);
9877
ded5303e1fde util.startup: Log configuration warnings at startup
Matthew Wild <mwild1@gmail.com>
parents: 9873
diff changeset
124 elseif err and #err > 0 then
ded5303e1fde util.startup: Log configuration warnings at startup
Matthew Wild <mwild1@gmail.com>
parents: 9873
diff changeset
125 config_warnings = err;
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 end
9214
8b2b8f1a911f util.startup: Set flag when config fully loaded
Matthew Wild <mwild1@gmail.com>
parents: 8958
diff changeset
127 prosody.config_loaded = true;
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 function startup.check_dependencies()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 if not dependencies.check_dependencies() then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 os.exit(1);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 -- luacheck: globals socket server
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 function startup.load_libraries()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 -- Load socket framework
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 -- luacheck: ignore 111/server 111/socket
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 socket = require "socket";
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 server = require "net.server"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 function startup.init_logging()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 -- Initialize logging
8721
b773b15fee71 util.startup: Set up event hooks for reloading logging here instead of in loggingmanager to simplify startup dependencies
Kim Alvefur <zash@zash.se>
parents: 8720
diff changeset
147 local loggingmanager = require "core.loggingmanager"
b773b15fee71 util.startup: Set up event hooks for reloading logging here instead of in loggingmanager to simplify startup dependencies
Kim Alvefur <zash@zash.se>
parents: 8720
diff changeset
148 loggingmanager.reload_logging();
9762
34988a408b74 util.startup: Always reload logging after config (fixes #1284)
Kim Alvefur <zash@zash.se>
parents: 9214
diff changeset
149 prosody.events.add_handler("config-reloaded", function ()
34988a408b74 util.startup: Always reload logging after config (fixes #1284)
Kim Alvefur <zash@zash.se>
parents: 9214
diff changeset
150 prosody.events.fire_event("reopen-log-files");
34988a408b74 util.startup: Always reload logging after config (fixes #1284)
Kim Alvefur <zash@zash.se>
parents: 9214
diff changeset
151 end);
8721
b773b15fee71 util.startup: Set up event hooks for reloading logging here instead of in loggingmanager to simplify startup dependencies
Kim Alvefur <zash@zash.se>
parents: 8720
diff changeset
152 prosody.events.add_handler("reopen-log-files", function ()
b773b15fee71 util.startup: Set up event hooks for reloading logging here instead of in loggingmanager to simplify startup dependencies
Kim Alvefur <zash@zash.se>
parents: 8720
diff changeset
153 loggingmanager.reload_logging();
b773b15fee71 util.startup: Set up event hooks for reloading logging here instead of in loggingmanager to simplify startup dependencies
Kim Alvefur <zash@zash.se>
parents: 8720
diff changeset
154 prosody.events.fire_event("logging-reloaded");
b773b15fee71 util.startup: Set up event hooks for reloading logging here instead of in loggingmanager to simplify startup dependencies
Kim Alvefur <zash@zash.se>
parents: 8720
diff changeset
155 end);
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157
9873
dfaeea570f7e util.startup: Give function a more generic name so it can apply to all warnings
Matthew Wild <mwild1@gmail.com>
parents: 9762
diff changeset
158 function startup.log_startup_warnings()
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 dependencies.log_warnings();
9878
dd61201fc5af util.startup: Don't die if there are no config warnings to log (thanks buildbot)
Matthew Wild <mwild1@gmail.com>
parents: 9877
diff changeset
160 if config_warnings then
dd61201fc5af util.startup: Don't die if there are no config warnings to log (thanks buildbot)
Matthew Wild <mwild1@gmail.com>
parents: 9877
diff changeset
161 for _, warning in ipairs(config_warnings) do
dd61201fc5af util.startup: Don't die if there are no config warnings to log (thanks buildbot)
Matthew Wild <mwild1@gmail.com>
parents: 9877
diff changeset
162 log("warn", "Configuration warning: %s", warning);
dd61201fc5af util.startup: Don't die if there are no config warnings to log (thanks buildbot)
Matthew Wild <mwild1@gmail.com>
parents: 9877
diff changeset
163 end
9877
ded5303e1fde util.startup: Log configuration warnings at startup
Matthew Wild <mwild1@gmail.com>
parents: 9873
diff changeset
164 end
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 function startup.sanity_check()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168 for host, host_config in pairs(config.getconfig()) do
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 if host ~= "*"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 and host_config.enabled ~= false
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 and not host_config.component_module then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 return;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 log("error", "No enabled VirtualHost entries found in the config file.");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 log("error", "At least one active host is required for Prosody to function. Exiting...");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177 os.exit(1);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
179
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180 function startup.sandbox_require()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181 -- Replace require() with one that doesn't pollute _G, required
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
182 -- for neat sandboxing of modules
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
183 -- luacheck: ignore 113/getfenv 111/require
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 local _realG = _G;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185 local _real_require = require;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186 local getfenv = getfenv or function (f)
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187 -- FIXME: This is a hack to replace getfenv() in Lua 5.2
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188 local name, env = debug.getupvalue(debug.getinfo(f or 1).func, 1);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189 if name == "_ENV" then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
190 return env;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
191 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
192 end
8638
f8f45bbbd8ba util.startup: Ignore various globals being read and written as part of startup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8637
diff changeset
193 function require(...) -- luacheck: ignore 121
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
194 local curr_env = getfenv(2);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
195 local curr_env_mt = getmetatable(curr_env);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
196 local _realG_mt = getmetatable(_realG);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
197 if curr_env_mt and curr_env_mt.__index and not curr_env_mt.__newindex and _realG_mt then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
198 local old_newindex, old_index;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
199 old_newindex, _realG_mt.__newindex = _realG_mt.__newindex, curr_env;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
200 old_index, _realG_mt.__index = _realG_mt.__index, function (_G, k) -- luacheck: ignore 212/_G
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
201 return rawget(curr_env, k);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
202 end;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
203 local ret = _real_require(...);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
204 _realG_mt.__newindex = old_newindex;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
205 _realG_mt.__index = old_index;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
206 return ret;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
207 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
208 return _real_require(...);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
209 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
210 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
211
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
212 function startup.set_function_metatable()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
213 local mt = {};
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
214 function mt.__index(f, upvalue)
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
215 local i, name, value = 0;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
216 repeat
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
217 i = i + 1;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
218 name, value = debug.getupvalue(f, i);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
219 until name == upvalue or name == nil;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
220 return value;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
221 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
222 function mt.__newindex(f, upvalue, value)
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
223 local i, name = 0;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
224 repeat
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
225 i = i + 1;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
226 name = debug.getupvalue(f, i);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
227 until name == upvalue or name == nil;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
228 if name then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
229 debug.setupvalue(f, i, value);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
230 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
231 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
232 function mt.__tostring(f)
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
233 local info = debug.getinfo(f);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
234 return ("function(%s:%d)"):format(info.short_src:match("[^\\/]*$"), info.linedefined);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
235 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
236 debug.setmetatable(function() end, mt);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
237 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
238
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
239 function startup.detect_platform()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
240 prosody.platform = "unknown";
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
241 if os.getenv("WINDIR") then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
242 prosody.platform = "windows";
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
243 elseif package.config:sub(1,1) == "/" then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
244 prosody.platform = "posix";
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
245 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
246 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
247
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
248 function startup.detect_installed()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
249 prosody.installed = nil;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
250 if CFG_SOURCEDIR and (prosody.platform == "windows" or CFG_SOURCEDIR:match("^/")) then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
251 prosody.installed = true;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
252 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
253 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
254
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
255 function startup.init_global_state()
8638
f8f45bbbd8ba util.startup: Ignore various globals being read and written as part of startup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8637
diff changeset
256 -- luacheck: ignore 121
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
257 prosody.bare_sessions = {};
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
258 prosody.full_sessions = {};
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
259 prosody.hosts = {};
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
260
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
261 -- COMPAT: These globals are deprecated
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
262 -- luacheck: ignore 111/bare_sessions 111/full_sessions 111/hosts
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
263 bare_sessions = prosody.bare_sessions;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
264 full_sessions = prosody.full_sessions;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
265 hosts = prosody.hosts;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
266
8698
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
267 prosody.paths = { source = CFG_SOURCEDIR, config = CFG_CONFIGDIR or ".",
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
268 plugins = CFG_PLUGINDIR or "plugins", data = "data" };
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
269
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
270 prosody.arg = _G.arg;
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
271
8720
dba17a70fd22 util.startup: Initialize prosody.log / _G.log here instead of in loggingmanager to reduce dependencies
Kim Alvefur <zash@zash.se>
parents: 8719
diff changeset
272 _G.log = logger.init("general");
dba17a70fd22 util.startup: Initialize prosody.log / _G.log here instead of in loggingmanager to reduce dependencies
Kim Alvefur <zash@zash.se>
parents: 8719
diff changeset
273 prosody.log = logger.init("general");
dba17a70fd22 util.startup: Initialize prosody.log / _G.log here instead of in loggingmanager to reduce dependencies
Kim Alvefur <zash@zash.se>
parents: 8719
diff changeset
274
8698
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
275 startup.detect_platform();
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
276 startup.detect_installed();
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
277 _G.prosody = prosody;
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
278 end
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
279
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
280 function startup.setup_datadir()
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
281 prosody.paths.data = config.get("*", "data_path") or CFG_DATADIR or "data";
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
282 end
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
283
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
284 function startup.setup_plugindir()
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
285 local custom_plugin_paths = config.get("*", "plugin_paths");
10173
0513dd2830b7 util.startup: The .setup_plugindir function now correctly sets a default/specified path for custom plugins
João Duarte <jvsDuarte08@gmail.com>
parents: 10171
diff changeset
286 local path_sep = package.config:sub(3,3);
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
287 if custom_plugin_paths then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
288 -- path1;path2;path3;defaultpath...
8638
f8f45bbbd8ba util.startup: Ignore various globals being read and written as part of startup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8637
diff changeset
289 -- luacheck: ignore 111
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
290 CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins");
8733
6a234e77c99f util.startup: Fix traceback due to both plugin path becoming nil if plugin_paths is unset
Kim Alvefur <zash@zash.se>
parents: 8728
diff changeset
291 prosody.paths.plugins = CFG_PLUGINDIR;
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
292 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
293 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
294
10404
29c10930a7b2 util.startup: Split plugin installer path setup into a separate function
Kim Alvefur <zash@zash.se>
parents: 10391
diff changeset
295 function startup.setup_plugin_install_path()
29c10930a7b2 util.startup: Split plugin installer path setup into a separate function
Kim Alvefur <zash@zash.se>
parents: 10391
diff changeset
296 local installer_plugin_path = config.get("*", "installer_plugin_path") or "custom_plugins";
29c10930a7b2 util.startup: Split plugin installer path setup into a separate function
Kim Alvefur <zash@zash.se>
parents: 10391
diff changeset
297 local path_sep = package.config:sub(3,3);
10405
e7f5735f19e1 util.startup: Disable plugin installer path creation for now (see comments)
Kim Alvefur <zash@zash.se>
parents: 10404
diff changeset
298 -- TODO Figure out what this should be relative to, because CWD could be anywhere
10404
29c10930a7b2 util.startup: Split plugin installer path setup into a separate function
Kim Alvefur <zash@zash.se>
parents: 10391
diff changeset
299 installer_plugin_path = config.resolve_relative_path(require "lfs".currentdir(), installer_plugin_path);
10405
e7f5735f19e1 util.startup: Disable plugin installer path creation for now (see comments)
Kim Alvefur <zash@zash.se>
parents: 10404
diff changeset
300 -- TODO Can probably move directory creation to the install command
10404
29c10930a7b2 util.startup: Split plugin installer path setup into a separate function
Kim Alvefur <zash@zash.se>
parents: 10391
diff changeset
301 require "lfs".mkdir(installer_plugin_path);
29c10930a7b2 util.startup: Split plugin installer path setup into a separate function
Kim Alvefur <zash@zash.se>
parents: 10391
diff changeset
302 require"util.paths".complement_lua_path(installer_plugin_path);
29c10930a7b2 util.startup: Split plugin installer path setup into a separate function
Kim Alvefur <zash@zash.se>
parents: 10391
diff changeset
303 -- luacheck: ignore 111
10173
0513dd2830b7 util.startup: The .setup_plugindir function now correctly sets a default/specified path for custom plugins
João Duarte <jvsDuarte08@gmail.com>
parents: 10171
diff changeset
304 CFG_PLUGINDIR = installer_plugin_path..path_sep..(CFG_PLUGINDIR or "plugins");
10171
628e238feb04 util.startup: Removed unnecessary if clause at startup.set_plugindir
João Duarte <jvsDuarte08@gmail.com>
parents: 10163
diff changeset
305 prosody.paths.plugins = CFG_PLUGINDIR;
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
306 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
307
8664
d49acc9a8da2 util.startup: Fix chdir() to use correct path variable
Matthew Wild <mwild1@gmail.com>
parents: 8653
diff changeset
308 function startup.chdir()
d49acc9a8da2 util.startup: Fix chdir() to use correct path variable
Matthew Wild <mwild1@gmail.com>
parents: 8653
diff changeset
309 if prosody.installed then
10390
82705ec87253 util.startup: Ensure prosody.paths are absolute (see #1430)
Kim Alvefur <zash@zash.se>
parents: 10389
diff changeset
310 local lfs = require "lfs";
82705ec87253 util.startup: Ensure prosody.paths are absolute (see #1430)
Kim Alvefur <zash@zash.se>
parents: 10389
diff changeset
311 -- Ensure paths are absolute, not relative to the working directory which we're about to change
82705ec87253 util.startup: Ensure prosody.paths are absolute (see #1430)
Kim Alvefur <zash@zash.se>
parents: 10389
diff changeset
312 local cwd = lfs.currentdir();
82705ec87253 util.startup: Ensure prosody.paths are absolute (see #1430)
Kim Alvefur <zash@zash.se>
parents: 10389
diff changeset
313 prosody.paths.source = config.resolve_relative_path(cwd, prosody.paths.source);
82705ec87253 util.startup: Ensure prosody.paths are absolute (see #1430)
Kim Alvefur <zash@zash.se>
parents: 10389
diff changeset
314 prosody.paths.config = config.resolve_relative_path(cwd, prosody.paths.config);
82705ec87253 util.startup: Ensure prosody.paths are absolute (see #1430)
Kim Alvefur <zash@zash.se>
parents: 10389
diff changeset
315 prosody.paths.data = config.resolve_relative_path(cwd, prosody.paths.data);
8664
d49acc9a8da2 util.startup: Fix chdir() to use correct path variable
Matthew Wild <mwild1@gmail.com>
parents: 8653
diff changeset
316 -- Change working directory to data path.
10390
82705ec87253 util.startup: Ensure prosody.paths are absolute (see #1430)
Kim Alvefur <zash@zash.se>
parents: 10389
diff changeset
317 lfs.chdir(prosody.paths.data);
8664
d49acc9a8da2 util.startup: Fix chdir() to use correct path variable
Matthew Wild <mwild1@gmail.com>
parents: 8653
diff changeset
318 end
d49acc9a8da2 util.startup: Fix chdir() to use correct path variable
Matthew Wild <mwild1@gmail.com>
parents: 8653
diff changeset
319 end
d49acc9a8da2 util.startup: Fix chdir() to use correct path variable
Matthew Wild <mwild1@gmail.com>
parents: 8653
diff changeset
320
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
321 function startup.add_global_prosody_functions()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
322 -- Function to reload the config file
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
323 function prosody.reload_config()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
324 log("info", "Reloading configuration file");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
325 prosody.events.fire_event("reloading-config");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
326 local ok, level, err = config.load(prosody.config_file);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
327 if not ok then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
328 if level == "parser" then
10108
659ffa03f1e7 util.startup: Remove tostring call from logging
Kim Alvefur <zash@zash.se>
parents: 9878
diff changeset
329 log("error", "There was an error parsing the configuration file: %s", err);
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
330 elseif level == "file" then
10108
659ffa03f1e7 util.startup: Remove tostring call from logging
Kim Alvefur <zash@zash.se>
parents: 9878
diff changeset
331 log("error", "Couldn't read the config file when trying to reload: %s", err);
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
332 end
8692
a55574754e5f configmanager: Move firing of the 'config-reloaded' event into util.startup (fixes #1117)
Kim Alvefur <zash@zash.se>
parents: 8688
diff changeset
333 else
a55574754e5f configmanager: Move firing of the 'config-reloaded' event into util.startup (fixes #1117)
Kim Alvefur <zash@zash.se>
parents: 8688
diff changeset
334 prosody.events.fire_event("config-reloaded", {
a55574754e5f configmanager: Move firing of the 'config-reloaded' event into util.startup (fixes #1117)
Kim Alvefur <zash@zash.se>
parents: 8688
diff changeset
335 filename = prosody.config_file,
a55574754e5f configmanager: Move firing of the 'config-reloaded' event into util.startup (fixes #1117)
Kim Alvefur <zash@zash.se>
parents: 8688
diff changeset
336 config = config.getconfig(),
a55574754e5f configmanager: Move firing of the 'config-reloaded' event into util.startup (fixes #1117)
Kim Alvefur <zash@zash.se>
parents: 8688
diff changeset
337 });
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
338 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
339 return ok, (err and tostring(level)..": "..tostring(err)) or nil;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
340 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
341
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
342 -- Function to reopen logfiles
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
343 function prosody.reopen_logfiles()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
344 log("info", "Re-opening log files");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
345 prosody.events.fire_event("reopen-log-files");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
346 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
347
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
348 -- Function to initiate prosody shutdown
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
349 function prosody.shutdown(reason, code)
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
350 log("info", "Shutting down: %s", reason or "unknown reason");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
351 prosody.shutdown_reason = reason;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
352 prosody.shutdown_code = code;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
353 prosody.events.fire_event("server-stopping", {
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
354 reason = reason;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
355 code = code;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
356 });
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
357 server.setquitting(true);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
358 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
359 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
360
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
361 function startup.load_secondary_libraries()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
362 --- Load and initialise core modules
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
363 require "util.import"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
364 require "util.xmppstream"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
365 require "core.stanza_router"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
366 require "core.statsmanager"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
367 require "core.hostmanager"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
368 require "core.portmanager"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
369 require "core.modulemanager"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
370 require "core.usermanager"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
371 require "core.rostermanager"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
372 require "core.sessionmanager"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
373 package.loaded['core.componentmanager'] = setmetatable({},{__index=function()
8958
b10a37f6f75f util.startup: Add a comment marking some compat code
Kim Alvefur <zash@zash.se>
parents: 8882
diff changeset
374 -- COMPAT which version?
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
375 log("warn", "componentmanager is deprecated: %s", debug.traceback():match("\n[^\n]*\n[ \t]*([^\n]*)"));
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
376 return function() end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
377 end});
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
378
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
379 require "util.array"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
380 require "util.datetime"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
381 require "util.iterators"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
382 require "util.timer"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
383 require "util.helpers"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
384
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
385 pcall(require, "util.signal") -- Not on Windows
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
386
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
387 -- Commented to protect us from
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
388 -- the second kind of people
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
389 --[[
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
390 pcall(require, "remdebug.engine");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
391 if remdebug then remdebug.engine.start() end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
392 ]]
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
393
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
394 require "util.stanza"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
395 require "util.jid"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
396 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
397
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
398 function startup.init_http_client()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
399 local http = require "net.http"
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
400 local config_ssl = config.get("*", "ssl") or {}
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
401 local https_client = config.get("*", "client_https_ssl")
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
402 http.default.options.sslctx = require "core.certmanager".create_context("client_https port 0", "client",
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
403 { capath = config_ssl.capath, cafile = config_ssl.cafile, verify = "peer", }, https_client);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
404 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
405
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
406 function startup.init_data_store()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
407 require "core.storagemanager";
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
408 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
409
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
410 function startup.prepare_to_start()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
411 log("info", "Prosody is using the %s backend for connection handling", server.get_backend());
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
412 -- Signal to modules that we are ready to start
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
413 prosody.events.fire_event("server-starting");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
414 prosody.start_time = os.time();
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
415 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
416
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
417 function startup.init_global_protection()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
418 -- Catch global accesses
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
419 -- luacheck: ignore 212/t
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
420 local locked_globals_mt = {
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
421 __index = function (t, k) log("warn", "%s", debug.traceback("Attempt to read a non-existent global '"..tostring(k).."'", 2)); end;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
422 __newindex = function (t, k, v) error("Attempt to set a global: "..tostring(k).." = "..tostring(v), 2); end;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
423 };
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
424
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
425 function prosody.unlock_globals()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
426 setmetatable(_G, nil);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
427 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
428
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
429 function prosody.lock_globals()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
430 setmetatable(_G, locked_globals_mt);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
431 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
432
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
433 -- And lock now...
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
434 prosody.lock_globals();
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
435 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
436
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
437 function startup.read_version()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
438 -- Try to determine version
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
439 local version_file = io.open((CFG_SOURCEDIR or ".").."/prosody.version");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
440 prosody.version = "unknown";
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
441 if version_file then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
442 prosody.version = version_file:read("*a"):gsub("%s*$", "");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
443 version_file:close();
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
444 if #prosody.version == 12 and prosody.version:match("^[a-f0-9]+$") then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
445 prosody.version = "hg:"..prosody.version;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
446 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
447 else
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
448 local hg = require"util.mercurial";
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
449 local hgid = hg.check_id(CFG_SOURCEDIR or ".");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
450 if hgid then prosody.version = "hg:" .. hgid; end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
451 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
452 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
453
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
454 function startup.log_greeting()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
455 log("info", "Hello and welcome to Prosody version %s", prosody.version);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
456 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
457
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
458 function startup.notify_started()
8637
c8368c7c81a1 util.startup: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8636
diff changeset
459 prosody.events.fire_event("server-started");
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
460 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
461
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
462 -- Override logging config (used by prosodyctl)
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
463 function startup.force_console_logging()
8666
57780ba1938f util.startup: Move original_logging_config to a local variable
Matthew Wild <mwild1@gmail.com>
parents: 8665
diff changeset
464 original_logging_config = config.get("*", "log");
8882
a420b386a72a Merge 0.10->trunk
Matthew Wild <mwild1@gmail.com>
parents: 8756
diff changeset
465 config.set("*", "log", { { levels = { min = os.getenv("PROSODYCTL_LOG_LEVEL") or "info" }, to = "console" } });
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
466 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
467
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
468 function startup.switch_user()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
469 -- Switch away from root and into the prosody user --
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
470 -- NOTE: This function is only used by prosodyctl.
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
471 -- The prosody process is built with the assumption that
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
472 -- it is already started as the appropriate user.
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
473
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
474 local want_pposix_version = "0.4.0";
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
475 local have_pposix, pposix = pcall(require, "util.pposix");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
476
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
477 if have_pposix and pposix then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
478 if pposix._VERSION ~= want_pposix_version then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
479 print(string.format("Unknown version (%s) of binary pposix module, expected %s",
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
480 tostring(pposix._VERSION), want_pposix_version));
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
481 os.exit(1);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
482 end
8672
86b12ae8d427 util.startup: Expose user switching information via prosody global object
Matthew Wild <mwild1@gmail.com>
parents: 8667
diff changeset
483 prosody.current_uid = pposix.getuid();
10597
25a3c8134b0a prosody/util.startup: Switch to parse_args() for --root and --config
Matthew Wild <mwild1@gmail.com>
parents: 10596
diff changeset
484 local arg_root = prosody.opts.root;
8672
86b12ae8d427 util.startup: Expose user switching information via prosody global object
Matthew Wild <mwild1@gmail.com>
parents: 8667
diff changeset
485 if prosody.current_uid == 0 and config.get("*", "run_as_root") ~= true and not arg_root then
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
486 -- We haz root!
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
487 local desired_user = config.get("*", "prosody_user") or "prosody";
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
488 local desired_group = config.get("*", "prosody_group") or desired_user;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
489 local ok, err = pposix.setgid(desired_group);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
490 if ok then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
491 ok, err = pposix.initgroups(desired_user);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
492 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
493 if ok then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
494 ok, err = pposix.setuid(desired_user);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
495 if ok then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
496 -- Yay!
8672
86b12ae8d427 util.startup: Expose user switching information via prosody global object
Matthew Wild <mwild1@gmail.com>
parents: 8667
diff changeset
497 prosody.switched_user = true;
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
498 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
499 end
8672
86b12ae8d427 util.startup: Expose user switching information via prosody global object
Matthew Wild <mwild1@gmail.com>
parents: 8667
diff changeset
500 if not prosody.switched_user then
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
501 -- Boo!
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
502 print("Warning: Couldn't switch to Prosody user/group '"..tostring(desired_user).."'/'"..tostring(desired_group).."': "..tostring(err));
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
503 else
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
504 -- Make sure the Prosody user can read the config
10532
19ec384eb782 util.startup: Ignore unused errno variable [luacheck]
Kim Alvefur <zash@zash.se>
parents: 10405
diff changeset
505 local conf, err, errno = io.open(prosody.config_file); --luacheck: ignore 211/errno
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
506 if conf then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
507 conf:close();
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
508 else
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
509 print("The config file is not readable by the '"..desired_user.."' user.");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
510 print("Prosody will not be able to read it.");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
511 print("Error was "..err);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
512 os.exit(1);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
513 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
514 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
515 end
8637
c8368c7c81a1 util.startup: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8636
diff changeset
516
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
517 -- Set our umask to protect data files
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
518 pposix.umask(config.get("*", "umask") or "027");
8667
a05d36075c6a util.startup: Fix variable usage [luacheck]
Matthew Wild <mwild1@gmail.com>
parents: 8666
diff changeset
519 pposix.setenv("HOME", prosody.paths.data);
a05d36075c6a util.startup: Fix variable usage [luacheck]
Matthew Wild <mwild1@gmail.com>
parents: 8666
diff changeset
520 pposix.setenv("PROSODY_CONFIG", prosody.config_file);
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
521 else
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
522 print("Error: Unable to load pposix module. Check that Prosody is installed correctly.")
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
523 print("For more help send the below error to us through https://prosody.im/discuss");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
524 print(tostring(pposix))
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
525 os.exit(1);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
526 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
527 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
528
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
529 function startup.check_unwriteable()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
530 local function test_writeable(filename)
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
531 local f, err = io.open(filename, "a");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
532 if not f then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
533 return false, err;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
534 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
535 f:close();
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
536 return true;
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
537 end
8637
c8368c7c81a1 util.startup: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8636
diff changeset
538
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
539 local unwriteable_files = {};
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
540 if type(original_logging_config) == "string" and original_logging_config:sub(1,1) ~= "*" then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
541 local ok, err = test_writeable(original_logging_config);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
542 if not ok then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
543 table.insert(unwriteable_files, err);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
544 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
545 elseif type(original_logging_config) == "table" then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
546 for _, rule in ipairs(original_logging_config) do
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
547 if rule.filename then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
548 local ok, err = test_writeable(rule.filename);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
549 if not ok then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
550 table.insert(unwriteable_files, err);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
551 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
552 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
553 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
554 end
8637
c8368c7c81a1 util.startup: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8636
diff changeset
555
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
556 if #unwriteable_files > 0 then
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
557 print("One of more of the Prosody log files are not");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
558 print("writeable, please correct the errors and try");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
559 print("starting prosodyctl again.");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
560 print("");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
561 for _, err in ipairs(unwriteable_files) do
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
562 print(err);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
563 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
564 print("");
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
565 os.exit(1);
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
566 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
567 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
568
8673
6aeed79d9283 util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents: 8672
diff changeset
569 function startup.make_host(hostname)
6aeed79d9283 util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents: 8672
diff changeset
570 return {
6aeed79d9283 util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents: 8672
diff changeset
571 type = "local",
6aeed79d9283 util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents: 8672
diff changeset
572 events = prosody.events,
6aeed79d9283 util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents: 8672
diff changeset
573 modules = {},
6aeed79d9283 util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents: 8672
diff changeset
574 sessions = {},
6aeed79d9283 util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents: 8672
diff changeset
575 users = require "core.usermanager".new_null_provider(hostname)
6aeed79d9283 util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents: 8672
diff changeset
576 };
6aeed79d9283 util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents: 8672
diff changeset
577 end
6aeed79d9283 util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents: 8672
diff changeset
578
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
579 function startup.make_dummy_hosts()
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
580 -- When running under prosodyctl, we don't want to
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
581 -- fully initialize the server, so we populate prosody.hosts
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
582 -- with just enough things for most code to work correctly
8638
f8f45bbbd8ba util.startup: Ignore various globals being read and written as part of startup [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8637
diff changeset
583 -- luacheck: ignore 122/hosts
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
584 prosody.core_post_stanza = function () end; -- TODO: mod_router!
8637
c8368c7c81a1 util.startup: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8636
diff changeset
585
8639
070a77c15f63 util.startup: Remove unused loop variable [luacheck]
Kim Alvefur <zash@zash.se>
parents: 8638
diff changeset
586 for hostname in pairs(config.getconfig()) do
8715
25d8d6091ec3 util.startup: Access the hosts table via the prosody global for consistency
Kim Alvefur <zash@zash.se>
parents: 8713
diff changeset
587 prosody.hosts[hostname] = startup.make_host(hostname);
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
588 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
589 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
590
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
591 -- prosodyctl only
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
592 function startup.prosodyctl()
10597
25a3c8134b0a prosody/util.startup: Switch to parse_args() for --root and --config
Matthew Wild <mwild1@gmail.com>
parents: 10596
diff changeset
593 startup.parse_args();
8699
580c13ed0ca1 util.startup: Initialize the 'prosody' global earlier (various things needs the global util.events instance)
Kim Alvefur <zash@zash.se>
parents: 8698
diff changeset
594 startup.init_global_state();
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
595 startup.read_config();
8755
857d8f38a010 util.startup: Force console logging before initializing logging (see 2fdeb979cc7c)
Kim Alvefur <zash@zash.se>
parents: 8748
diff changeset
596 startup.force_console_logging();
8748
2fdeb979cc7c util.startup: Initialize logging immediately after configuration is read (which is how it used to work)
Matthew Wild <mwild1@gmail.com>
parents: 8734
diff changeset
597 startup.init_logging();
8698
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
598 startup.setup_plugindir();
10405
e7f5735f19e1 util.startup: Disable plugin installer path creation for now (see comments)
Kim Alvefur <zash@zash.se>
parents: 10404
diff changeset
599 -- startup.setup_plugin_install_path();
8698
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
600 startup.setup_datadir();
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
601 startup.chdir();
8688
019b4b3dd5ad util.startup: Read version for prosodyctl (restores version in 'about' command)
Kim Alvefur <zash@zash.se>
parents: 8682
diff changeset
602 startup.read_version();
8665
4b260a3f8b94 util.startup: Restore user switching
Matthew Wild <mwild1@gmail.com>
parents: 8664
diff changeset
603 startup.switch_user();
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
604 startup.check_dependencies();
9873
dfaeea570f7e util.startup: Give function a more generic name so it can apply to all warnings
Matthew Wild <mwild1@gmail.com>
parents: 9762
diff changeset
605 startup.log_startup_warnings();
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
606 startup.check_unwriteable();
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
607 startup.load_libraries();
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
608 startup.init_http_client();
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
609 startup.make_dummy_hosts();
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
610 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
611
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
612 function startup.prosody()
8682
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
613 -- These actions are in a strict order, as many depend on
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
614 -- previous steps to have already been performed
10597
25a3c8134b0a prosody/util.startup: Switch to parse_args() for --root and --config
Matthew Wild <mwild1@gmail.com>
parents: 10596
diff changeset
615 startup.parse_args();
8699
580c13ed0ca1 util.startup: Initialize the 'prosody' global earlier (various things needs the global util.events instance)
Kim Alvefur <zash@zash.se>
parents: 8698
diff changeset
616 startup.init_global_state();
8682
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
617 startup.read_config();
8748
2fdeb979cc7c util.startup: Initialize logging immediately after configuration is read (which is how it used to work)
Matthew Wild <mwild1@gmail.com>
parents: 8734
diff changeset
618 startup.init_logging();
8682
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
619 startup.sanity_check();
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
620 startup.sandbox_require();
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
621 startup.set_function_metatable();
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
622 startup.check_dependencies();
8719
0cb84aafeee6 util.startup: Initialize logging earlier, so that messages from eg net.server are shown
Kim Alvefur <zash@zash.se>
parents: 8715
diff changeset
623 startup.init_logging();
8682
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
624 startup.load_libraries();
8698
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
625 startup.setup_plugindir();
10405
e7f5735f19e1 util.startup: Disable plugin installer path creation for now (see comments)
Kim Alvefur <zash@zash.se>
parents: 10404
diff changeset
626 -- startup.setup_plugin_install_path();
8698
0499f3da0ec4 util.startup: Factor out processing of plugin and data paths into a separate functions
Kim Alvefur <zash@zash.se>
parents: 8692
diff changeset
627 startup.setup_datadir();
8682
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
628 startup.chdir();
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
629 startup.add_global_prosody_functions();
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
630 startup.read_version();
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
631 startup.log_greeting();
9873
dfaeea570f7e util.startup: Give function a more generic name so it can apply to all warnings
Matthew Wild <mwild1@gmail.com>
parents: 9762
diff changeset
632 startup.log_startup_warnings();
8682
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
633 startup.load_secondary_libraries();
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
634 startup.init_http_client();
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
635 startup.init_data_store();
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
636 startup.init_global_protection();
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
637 startup.prepare_to_start();
151ecd18d624 prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents: 8673
diff changeset
638 startup.notify_started();
8635
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
639 end
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
640
47e3b8b6f17a prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
641 return startup;