Software /
code /
prosody
Annotate
util/startup.lua @ 8682:151ecd18d624
prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 23 Mar 2018 14:18:27 +0000 |
parent | 8673:6aeed79d9283 |
child | 8688:019b4b3dd5ad |
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() }; |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local config = require "core.configmanager"; |
47e3b8b6f17a
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 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
|
10 |
8666
57780ba1938f
util.startup: Move original_logging_config to a local variable
Matthew Wild <mwild1@gmail.com>
parents:
8665
diff
changeset
|
11 local original_logging_config; |
57780ba1938f
util.startup: Move original_logging_config to a local variable
Matthew Wild <mwild1@gmail.com>
parents:
8665
diff
changeset
|
12 |
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
|
13 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
|
14 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
|
15 |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local 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
|
17 if arg[1] == "--config" and arg[2] 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
|
18 table.insert(filenames, arg[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
|
19 if CFG_CONFIGDIR 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
|
20 table.insert(filenames, CFG_CONFIGDIR.."/"..arg[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
|
21 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
|
22 table.remove(arg, 1); table.remove(arg, 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 prosody.config_file = filename; |
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
|
34 CFG_CONFIGDIR = filename:match("^(.*)[\\/][^\\/]*$"); -- 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 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
|
43 if level == "parser" 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
|
44 print("A problem occured while reading the 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 |
47e3b8b6f17a
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 -- 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
|
75 |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 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
|
77 -- 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
|
78 -- 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
|
79 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
|
80 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
|
81 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
|
82 |
47e3b8b6f17a
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 -- The global log() gets defined by loggingmanager |
47e3b8b6f17a
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 -- luacheck: ignore 113/log |
47e3b8b6f17a
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 |
47e3b8b6f17a
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 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
|
87 -- Initialize 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
|
88 require "core.loggingmanager" |
47e3b8b6f17a
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 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
|
90 |
47e3b8b6f17a
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 function startup.log_dependency_warnings() |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 dependencies.log_warnings(); |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 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
|
94 |
47e3b8b6f17a
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 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
|
96 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
|
97 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
|
98 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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 |
47e3b8b6f17a
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 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
|
109 -- 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
|
110 -- 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
|
111 -- 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
|
112 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
|
113 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
|
114 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
|
115 -- 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 _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
|
133 _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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 |
47e3b8b6f17a
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 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 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
|
164 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
|
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.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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
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 |
47e3b8b6f17a
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 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 |
47e3b8b6f17a
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 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
|
184 -- 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
|
185 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
|
186 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
|
187 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
|
188 |
47e3b8b6f17a
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 -- 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
|
190 -- 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
|
191 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
|
192 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
|
193 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
|
194 |
47e3b8b6f17a
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 data_path = config.get("*", "data_path") or CFG_DATADIR or "data"; |
47e3b8b6f17a
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 custom_plugin_paths = config.get("*", "plugin_paths"); |
47e3b8b6f17a
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 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
|
198 local path_sep = package.config:sub(3,3); |
47e3b8b6f17a
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 -- 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
|
200 -- 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
|
201 CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins"); |
47e3b8b6f17a
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 prosody.paths = { source = CFG_SOURCEDIR, config = CFG_CONFIGDIR 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
|
204 plugins = CFG_PLUGINDIR or "plugins", data = data_path }; |
47e3b8b6f17a
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 |
47e3b8b6f17a
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 prosody.arg = _G.arg; |
47e3b8b6f17a
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 |
47e3b8b6f17a
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 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
|
209 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
|
210 _G.prosody = 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
|
211 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
|
212 |
8664
d49acc9a8da2
util.startup: Fix chdir() to use correct path variable
Matthew Wild <mwild1@gmail.com>
parents:
8653
diff
changeset
|
213 function startup.chdir() |
d49acc9a8da2
util.startup: Fix chdir() to use correct path variable
Matthew Wild <mwild1@gmail.com>
parents:
8653
diff
changeset
|
214 if prosody.installed then |
d49acc9a8da2
util.startup: Fix chdir() to use correct path variable
Matthew Wild <mwild1@gmail.com>
parents:
8653
diff
changeset
|
215 -- Change working directory to data path. |
d49acc9a8da2
util.startup: Fix chdir() to use correct path variable
Matthew Wild <mwild1@gmail.com>
parents:
8653
diff
changeset
|
216 require "lfs".chdir(prosody.paths.data); |
d49acc9a8da2
util.startup: Fix chdir() to use correct path variable
Matthew Wild <mwild1@gmail.com>
parents:
8653
diff
changeset
|
217 end |
d49acc9a8da2
util.startup: Fix chdir() to use correct path variable
Matthew Wild <mwild1@gmail.com>
parents:
8653
diff
changeset
|
218 end |
d49acc9a8da2
util.startup: Fix chdir() to use correct path variable
Matthew Wild <mwild1@gmail.com>
parents:
8653
diff
changeset
|
219 |
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
|
220 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
|
221 -- 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 if level == "parser" 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
|
228 log("error", "There was an error parsing the configuration file: %s", 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
|
229 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
|
230 log("error", "Couldn't read the config file when trying to reload: %s", 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
|
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 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
|
233 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
|
234 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
|
235 |
47e3b8b6f17a
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 -- 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 |
47e3b8b6f17a
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 -- 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
|
243 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
|
244 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
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 }); |
47e3b8b6f17a
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 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
|
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.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
|
256 --- 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 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
|
267 package.loaded['core.componentmanager'] = setmetatable({},{__index=function() |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
268 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
|
269 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
|
270 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
|
271 |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
278 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
|
279 |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
280 -- 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
|
281 -- 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
|
282 --[[ |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
283 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
|
284 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
|
285 ]] |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
286 |
47e3b8b6f17a
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 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
|
288 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
|
289 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
|
290 |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
291 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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 { 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
|
297 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
|
298 |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
299 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
|
300 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
|
301 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
|
302 |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
303 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
|
304 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
|
305 -- 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
|
306 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
|
307 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
|
308 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
|
309 |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
310 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
|
311 -- 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
|
312 -- 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
|
313 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
|
314 __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
|
315 __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
|
316 }; |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
317 |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
318 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
|
319 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
|
320 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
|
321 |
47e3b8b6f17a
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 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
|
323 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
|
324 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
|
325 |
47e3b8b6f17a
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 -- 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
|
327 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
|
328 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
|
329 |
47e3b8b6f17a
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 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
|
331 -- 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 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
|
344 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
|
345 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
|
346 |
47e3b8b6f17a
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 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
|
348 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
|
349 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
|
350 |
47e3b8b6f17a
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 function startup.notify_started() |
8637
c8368c7c81a1
util.startup: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8636
diff
changeset
|
352 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
|
353 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
|
354 |
47e3b8b6f17a
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 -- 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
|
356 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
|
357 original_logging_config = config.get("*", "log"); |
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
|
358 config.set("*", "log", { { levels = { min="info" }, to = "console" } }); |
47e3b8b6f17a
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.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
|
362 -- 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
|
363 -- 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
|
364 -- 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
|
365 -- 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
|
366 |
47e3b8b6f17a
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 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
|
368 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
|
369 |
47e3b8b6f17a
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 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
|
371 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
|
372 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
|
373 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
|
374 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
|
375 end |
8672
86b12ae8d427
util.startup: Expose user switching information via prosody global object
Matthew Wild <mwild1@gmail.com>
parents:
8667
diff
changeset
|
376 prosody.current_uid = pposix.getuid(); |
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
|
377 local arg_root = arg[1] == "--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
|
378 if arg_root then table.remove(arg, 1); end |
8672
86b12ae8d427
util.startup: Expose user switching information via prosody global object
Matthew Wild <mwild1@gmail.com>
parents:
8667
diff
changeset
|
379 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
|
380 -- 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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 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
|
387 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
|
388 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
|
389 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
|
390 -- Yay! |
8672
86b12ae8d427
util.startup: Expose user switching information via prosody global object
Matthew Wild <mwild1@gmail.com>
parents:
8667
diff
changeset
|
391 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
|
392 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
|
393 end |
8672
86b12ae8d427
util.startup: Expose user switching information via prosody global object
Matthew Wild <mwild1@gmail.com>
parents:
8667
diff
changeset
|
394 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
|
395 -- 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
|
396 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
|
397 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
|
398 -- Make sure the Prosody user can read the config |
8667
a05d36075c6a
util.startup: Fix variable usage [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
8666
diff
changeset
|
399 local conf, err, errno = io.open(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
|
400 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
|
401 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
|
402 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
|
403 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
|
404 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
|
405 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
|
406 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
|
407 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
|
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 end |
8637
c8368c7c81a1
util.startup: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8636
diff
changeset
|
410 |
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
|
411 -- 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
|
412 pposix.umask(config.get("*", "umask") or "027"); |
8667
a05d36075c6a
util.startup: Fix variable usage [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
8666
diff
changeset
|
413 pposix.setenv("HOME", prosody.paths.data); |
a05d36075c6a
util.startup: Fix variable usage [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
8666
diff
changeset
|
414 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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 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
|
421 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 |
47e3b8b6f17a
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 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
|
424 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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 end |
8637
c8368c7c81a1
util.startup: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8636
diff
changeset
|
432 |
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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 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
|
441 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
|
442 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
|
443 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
|
444 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
|
445 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
|
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 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
|
448 end |
8637
c8368c7c81a1
util.startup: Trim trailing whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8636
diff
changeset
|
449 |
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
|
450 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
|
451 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
|
452 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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 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
|
458 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
|
459 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
|
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 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
|
462 |
8673
6aeed79d9283
util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents:
8672
diff
changeset
|
463 function startup.make_host(hostname) |
6aeed79d9283
util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents:
8672
diff
changeset
|
464 return { |
6aeed79d9283
util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents:
8672
diff
changeset
|
465 type = "local", |
6aeed79d9283
util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents:
8672
diff
changeset
|
466 events = prosody.events, |
6aeed79d9283
util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents:
8672
diff
changeset
|
467 modules = {}, |
6aeed79d9283
util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents:
8672
diff
changeset
|
468 sessions = {}, |
6aeed79d9283
util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents:
8672
diff
changeset
|
469 users = require "core.usermanager".new_null_provider(hostname) |
6aeed79d9283
util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents:
8672
diff
changeset
|
470 }; |
6aeed79d9283
util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents:
8672
diff
changeset
|
471 end |
6aeed79d9283
util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents:
8672
diff
changeset
|
472 |
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
|
473 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
|
474 -- 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
|
475 -- 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
|
476 -- 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
|
477 -- 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
|
478 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
|
479 |
8639
070a77c15f63
util.startup: Remove unused loop variable [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8638
diff
changeset
|
480 for hostname in pairs(config.getconfig()) do |
8673
6aeed79d9283
util.startup: Expose make_host() function
Matthew Wild <mwild1@gmail.com>
parents:
8672
diff
changeset
|
481 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
|
482 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
|
483 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
|
484 |
47e3b8b6f17a
prosody, prosodyctl, util.startup: Finally factor out startup-related and common code into a separate module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
485 -- 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
|
486 function startup.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
|
487 startup.read_config(); |
8665
4b260a3f8b94
util.startup: Restore user switching
Matthew Wild <mwild1@gmail.com>
parents:
8664
diff
changeset
|
488 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
|
489 startup.chdir(); |
8665
4b260a3f8b94
util.startup: Restore user switching
Matthew Wild <mwild1@gmail.com>
parents:
8664
diff
changeset
|
490 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
|
491 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
|
492 startup.force_console_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
|
493 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
|
494 startup.log_dependency_warnings(); |
47e3b8b6f17a
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 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
|
496 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
|
497 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
|
498 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
|
499 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
|
500 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
|
501 |
47e3b8b6f17a
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 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
|
503 -- 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
|
504 -- previous steps to have already been performed |
151ecd18d624
prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents:
8673
diff
changeset
|
505 startup.read_config(); |
151ecd18d624
prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents:
8673
diff
changeset
|
506 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
|
507 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
|
508 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
|
509 startup.check_dependencies(); |
151ecd18d624
prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents:
8673
diff
changeset
|
510 startup.load_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
|
511 startup.init_global_state(); |
151ecd18d624
prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents:
8673
diff
changeset
|
512 startup.init_logging(); |
151ecd18d624
prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents:
8673
diff
changeset
|
513 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
|
514 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
|
515 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
|
516 startup.log_greeting(); |
151ecd18d624
prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents:
8673
diff
changeset
|
517 startup.log_dependency_warnings(); |
151ecd18d624
prosody, util.startup: Switch from async.once() to long-lived thread, to avoid GC
Matthew Wild <mwild1@gmail.com>
parents:
8673
diff
changeset
|
518 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
|
519 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
|
520 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
|
521 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
|
522 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
|
523 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
|
524 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
|
525 |
47e3b8b6f17a
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 return startup; |