prosodyctl: Hide process management commands when init system should be used instead
authorKim Alvefur <zash@zash.se>
Tue, 21 Dec 2021 14:23:09 +0100
changeset 12107 fc297128c33a
parent 12106 949c2b52f51e
child 12108 29765ac7f72f
prosodyctl: Hide process management commands when init system should be used instead
prosodyctl
--- a/prosodyctl	Tue Dec 21 13:11:41 2021 +0100
+++ b/prosodyctl	Tue Dec 21 14:23:09 2021 +0100
@@ -226,14 +226,23 @@
 	return 1;
 end
 
+local function has_init_system() --> which
+	lfs = lfs or require"lfs";
+	if lfs.attributes("/etc/systemd") then
+		return "systemd";
+	elseif lfs.attributes("/etc/init.d/prosody") then
+		return "rc.d";
+	end
+end
+
 local function service_command_warning(service_command)
 	if prosody.installed and configmanager.get("*", "prosodyctl_service_warnings") ~= false then
 		show_warning("WARNING: Use of prosodyctl start/stop/restart/reload is not recommended");
 		show_warning("         if Prosody is managed by an init system - use that directly instead.");
-		lfs = lfs or require"lfs";
-		if lfs.attributes("/etc/systemd") then
+		local init = has_init_system()
+		if init == "systemd" then
 			show_warning("         e.g. systemctl %s prosody", service_command);
-		elseif lfs.attributes("/etc/init.d/prosody") then
+		elseif init == "rc.d" then
 			show_warning("         e.g. /etc/init.d/prosody %s", service_command);
 		end
 		show_warning("");
@@ -676,6 +685,13 @@
 
 		local done = {};
 
+		if prosody.installed and has_init_system() then
+			-- Hide start, stop, restart
+			done[table.remove(commands_order, 2)] = true;
+			done[table.remove(commands_order, 2)] = true;
+			done[table.remove(commands_order, 2)] = true;
+		end
+
 		for _, command_name in ipairs(commands_order) do
 			local command_func = commands[command_name];
 			if command_func then