# HG changeset patch # User Matthew Wild # Date 1278634197 -3600 # Node ID 7893055e54d1d816f0c804356c35c31aef89507e # Parent d50b6b3efad1dd8c17af18011884794dd3c1e54b prosodyctl: Warn and exit if any log files are not writeable, fixes #94 diff -r d50b6b3efad1 -r 7893055e54d1 prosodyctl --- a/prosodyctl Thu Jul 08 23:56:53 2010 +0100 +++ b/prosodyctl Fri Jul 09 01:09:57 2010 +0100 @@ -64,7 +64,7 @@ os.exit(1); end end - +local original_logging_config = config.get("*", "core", "log"); config.set("*", "core", "log", { { levels = { min="info" }, to = "console" } }); require "core.loggingmanager" @@ -111,6 +111,45 @@ print(tostring(pposix)) end +local function test_writeable(filename) + local f, err = io.open(filename, "a"); + if not f then + return false, err; + end + f:close(); + return true; +end + +local unwriteable_files = {}; +if type(original_logging_config) == "string" and original_logging_config:sub(1,1) ~= "*" then + local ok, err = test_writeable(original_logging_config); + if not ok then + table.insert(unwriteable_files, err); + end +elseif type(original_logging_config) == "table" then + for _, rule in ipairs(original_logging_config) do + if rule.filename then + local ok, err = test_writeable(rule.filename); + if not ok then + table.insert(unwriteable_files, err); + end + end + end +end + +if #unwriteable_files > 0 then + print("One of more of the Prosody log files are not"); + print("writeable, please correct the errors and try"); + print("starting prosodyctl again."); + print(""); + for _, err in ipairs(unwriteable_files) do + print(err); + end + print(""); + os.exit(1); +end + + local error_messages = setmetatable({ ["invalid-username"] = "The given username is invalid in a Jabber ID"; ["invalid-hostname"] = "The given hostname is invalid";