Changeset

11601:9483728f890f

mod_admin_shell: Add basic command that shows more info about loaded modules To show info about loaded modules. Inspired by the desire to know whether a module was loaded from the core set or 3rd party.
author Kim Alvefur <zash@zash.se>
date Sat, 12 Jun 2021 16:50:15 +0200
parents 11600:a02c277eb97a
children 11602:78ec0741c2bc
files plugins/mod_admin_shell.lua
diffstat 1 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_admin_shell.lua	Mon Jun 14 11:19:42 2021 +0100
+++ b/plugins/mod_admin_shell.lua	Sat Jun 12 16:50:15 2021 +0200
@@ -216,6 +216,7 @@
 	elseif section == "http" then
 		print [[http:list(hosts) - Show HTTP endpoints]]
 	elseif section == "module" then
+		print [[module:info(module, host) - Show information about a loaded module]]
 		print [[module:load(module, host) - Load the specified module on the specified host (or all hosts if none given)]]
 		print [[module:reload(module, host) - The same, but unloads and loads the module (saving state if the module supports it)]]
 		print [[module:unload(module, host) - The same, but just unloads the module from memory]]
@@ -392,6 +393,34 @@
 	return hosts_set;
 end
 
+function def_env.module:info(name, hosts)
+	if not name then
+		return nil, "module name expected";
+	end
+	local print = self.session.print;
+	hosts = get_hosts_with_module(hosts, name);
+	if hosts:empty() then
+		return false, "mod_" .. name .. " does not appear to be loaded on the specified hosts";
+	end
+
+	for host in hosts do
+		local mod = modulemanager.get_module(host, name);
+		if mod.module.host == "*" then
+			print("in global context");
+		elseif mod.module:get_host_type() == "local" then
+			print("on VirtualHost " .. mod.module.host);
+		elseif mod.module:get_host_type() == "component" then
+			local component_type = module:context(host):get_option_string("component_module", type);
+			if component_type == "component" then
+				component_type = "external";
+			end
+			print("on " .. component_type .. " Component " .. mod.module.host);
+		end
+		print("  path: " .. (mod.module.path or "n/a"));
+	end
+	return true;
+end
+
 function def_env.module:load(name, hosts, config)
 	hosts = get_hosts_with_module(hosts);