Comparison

prosodyctl @ 3339:7893055e54d1

prosodyctl: Warn and exit if any log files are not writeable, fixes #94
author Matthew Wild <mwild1@gmail.com>
date Fri, 09 Jul 2010 01:09:57 +0100
parent 3338:d50b6b3efad1
child 3471:482275e38224
comparison
equal deleted inserted replaced
3338:d50b6b3efad1 3339:7893055e54d1
62 print("**************************"); 62 print("**************************");
63 print(""); 63 print("");
64 os.exit(1); 64 os.exit(1);
65 end 65 end
66 end 66 end
67 67 local original_logging_config = config.get("*", "core", "log");
68 config.set("*", "core", "log", { { levels = { min="info" }, to = "console" } }); 68 config.set("*", "core", "log", { { levels = { min="info" }, to = "console" } });
69 69
70 require "core.loggingmanager" 70 require "core.loggingmanager"
71 71
72 if not require "util.dependencies".check_dependencies() then 72 if not require "util.dependencies".check_dependencies() then
108 else 108 else
109 print("Error: Unable to load pposix module. Check that Prosody is installed correctly.") 109 print("Error: Unable to load pposix module. Check that Prosody is installed correctly.")
110 print("For more help send the below error to us through http://prosody.im/discuss"); 110 print("For more help send the below error to us through http://prosody.im/discuss");
111 print(tostring(pposix)) 111 print(tostring(pposix))
112 end 112 end
113
114 local function test_writeable(filename)
115 local f, err = io.open(filename, "a");
116 if not f then
117 return false, err;
118 end
119 f:close();
120 return true;
121 end
122
123 local unwriteable_files = {};
124 if type(original_logging_config) == "string" and original_logging_config:sub(1,1) ~= "*" then
125 local ok, err = test_writeable(original_logging_config);
126 if not ok then
127 table.insert(unwriteable_files, err);
128 end
129 elseif type(original_logging_config) == "table" then
130 for _, rule in ipairs(original_logging_config) do
131 if rule.filename then
132 local ok, err = test_writeable(rule.filename);
133 if not ok then
134 table.insert(unwriteable_files, err);
135 end
136 end
137 end
138 end
139
140 if #unwriteable_files > 0 then
141 print("One of more of the Prosody log files are not");
142 print("writeable, please correct the errors and try");
143 print("starting prosodyctl again.");
144 print("");
145 for _, err in ipairs(unwriteable_files) do
146 print(err);
147 end
148 print("");
149 os.exit(1);
150 end
151
113 152
114 local error_messages = setmetatable({ 153 local error_messages = setmetatable({
115 ["invalid-username"] = "The given username is invalid in a Jabber ID"; 154 ["invalid-username"] = "The given username is invalid in a Jabber ID";
116 ["invalid-hostname"] = "The given hostname is invalid"; 155 ["invalid-hostname"] = "The given hostname is invalid";
117 ["no-password"] = "No password was supplied"; 156 ["no-password"] = "No password was supplied";