Changeset

13651:b9d369f77121

prosodyctl: Further deprecate start/stop/restart commands when installed Despite the warning we introduced, many people continue to try using prosodyctl to manage Prosody in the presence of systemctl (e.g. #1688). Also, despite the warning, prosodyctl proceeded with the operation. This means the commands could be invoked by accident, and cause a situation that is hard to recover from (needing to manually track down stray processes). This commit disables all the problematic commands by default, but this can still be overridden using --force or via a config option. We only perform this check when we believe Prosody has been "installed" for system-wide use (i.e. running it from a source directory is still supported).
author Matthew Wild <mwild1@gmail.com>
date Thu, 06 Feb 2025 14:51:31 +0000
parents 13650:9a66b53a5076
children 13652:a08065207ef0
files prosodyctl
diffstat 1 files changed, 35 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/prosodyctl	Thu Feb 06 14:47:45 2025 +0000
+++ b/prosodyctl	Thu Feb 06 14:51:31 2025 +0000
@@ -181,16 +181,30 @@
 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.");
+	if true or prosody.installed and configmanager.get("*", "prosodyctl_service_warnings") ~= false then
+		show_warning("ERROR: Use of 'prosodyctl %s' is disabled in this installation because", service_command);
+
 		local init = has_init_system()
-		if init == "systemd" then
-			show_warning("         e.g. systemctl %s prosody", service_command);
-		elseif init == "rc.d" then
-			show_warning("         e.g. /etc/init.d/prosody %s", service_command);
+		if init then
+			show_warning("       we detected that this system uses %s for managing services.", init);
+			show_warning("");
+			show_warning("       To avoid problems, use that directly instead. For example:");
+			show_warning("");
+			if init == "systemd" then
+				show_warning("          systemctl %s prosody", service_command);
+			elseif init == "rc.d" then
+				show_warning("          /etc/init.d/prosody %s", service_command);
+			end
+		else
+			show_warning("       it may conflict with your system's service manager.");
+			show_warning("");
 		end
-		show_warning("");
+
+		show_warning("       Proceeding to use prosodyctl may cause process management issues.");
+		show_warning("       You can pass --force to override this warning, or set");
+		show_warning("       prosodyctl_service_warnings = false in your global config.");
+
+		os.exit(1);
 	end
 end
 
@@ -200,7 +214,9 @@
 		show_usage([[start]], [[Start Prosody]]);
 		return 0;
 	end
-	service_command_warning("start");
+	if not opts.force then
+		service_command_warning("start");
+	end
 	local ok, ret = prosodyctl.isrunning();
 	if not ok then
 		show_message(error_messages[ret]);
@@ -301,7 +317,9 @@
 		return 0;
 	end
 
-	service_command_warning("stop");
+	if not opts.force then
+		service_command_warning("stop");
+	end
 
 	local ok, running = prosodyctl.isrunning();
 	if not ok then
@@ -343,7 +361,9 @@
 		return 1;
 	end
 
-	service_command_warning("restart");
+	if not opts.force then
+		service_command_warning("restart");
+	end
 
 	commands.stop(arg);
 	return commands.start(arg);
@@ -530,6 +550,10 @@
 		return 1;
 	end
 
+	if not opts.force then
+		service_command_warning("reload");
+	end
+
 	local ok, ret = prosodyctl.reload();
 	if ok then