From 0a93dccaa9fe20ace9e648eeac9cc155c3f668e9 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 6 Feb 2025 14:51:31 +0000 Subject: 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). --- prosodyctl | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'prosodyctl') diff --git a/prosodyctl b/prosodyctl index f8e12a0d..f1d46b55 100755 --- a/prosodyctl +++ b/prosodyctl @@ -181,16 +181,30 @@ local function has_init_system() --> which 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 @@ function commands.start(arg) 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 @@ function commands.stop(arg) 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 @@ function commands.restart(arg) 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 @@ function commands.reload(arg) return 1; end + if not opts.force then + service_command_warning("reload"); + end + local ok, ret = prosodyctl.reload(); if ok then -- cgit v1.2.3