Comparison

prosodyctl @ 5584:1d841117117c

prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
author Matthew Wild <mwild1@gmail.com>
date Fri, 17 May 2013 09:01:11 +0100
parent 5554:e91db0aac408
child 5585:3e097acf82de
comparison
equal deleted inserted replaced
5583:78dbece77ce8 5584:1d841117117c
774 end 774 end
775 end 775 end
776 show_usage("cert config|request|generate|key", "Helpers for generating X.509 certificates and keys.") 776 show_usage("cert config|request|generate|key", "Helpers for generating X.509 certificates and keys.")
777 end 777 end
778 778
779 function commands.check(arg)
780 local what = table.remove(arg, 1);
781 local array, set = require "util.array", require "util.set";
782 local it = require "util.iterators";
783 local ok = true;
784 if not what or what == "config" then
785 print("Checking config...");
786 local known_global_options = set.new({
787 "pidfile", "log", "plugin_paths", "prosody_user", "prosody_group", "daemonize",
788 "umask", "prosodyctl_timeout", "use_ipv6", "use_libevent", "network_settings"
789 });
790 local config = config.getconfig();
791 -- Check that we have any global options (caused by putting a host at the top)
792 if it.count(it.filter("log", pairs(config["*"]))) == 0 then
793 ok = false;
794 print("");
795 print(" No global options defined. Perhaps you have put a host definition at the top")
796 print(" of the config file? They should be at the bottom, see http://prosody.im/doc/configure#overview");
797 end
798 -- Check for global options under hosts
799 local global_options = set.new(it.to_array(it.keys(config["*"])));
800 for host, options in it.filter("*", pairs(config)) do
801 local host_options = set.new(it.to_array(it.keys(options)));
802 local misplaced_options = set.intersection(host_options, known_global_options);
803 for name in pairs(options) do
804 if name:match("^interfaces?")
805 or name:match("_ports?$") or name:match("_interfaces?$")
806 or name:match("_ssl$") then
807 misplaced_options:add(name);
808 end
809 end
810 if not misplaced_options:empty() then
811 ok = false;
812 print("");
813 local n = it.count(misplaced_options);
814 print(" You have "..n.." option"..(n>1 and "s " or " ").."set under "..host.." that should be");
815 print(" in the global section of the config file, above any VirtualHost or Component definitions,")
816 print(" see http://prosody.im/doc/configure#overview for more information.")
817 print("");
818 print(" You need to move the following option"..(n>1 and "s" or "")..": "..table.concat(it.to_array(misplaced_options), ", "));
819 end
820 end
821 print("Done.");
822 end
823 if not ok then
824 print("Problems found, see above.");
825 else
826 print("All checks passed, congratulations!");
827 end
828 return ok and 0 or 2;
829 end
830
779 --------------------- 831 ---------------------
780 832
781 if command and command:match("^mod_") then -- Is a command in a module 833 if command and command:match("^mod_") then -- Is a command in a module
782 local module_name = command:match("^mod_(.+)"); 834 local module_name = command:match("^mod_(.+)");
783 local ret, err = modulemanager.load("*", module_name); 835 local ret, err = modulemanager.load("*", module_name);