Software / code / prosody
Comparison
prosodyctl @ 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 |
| parent | 13650:9a66b53a5076 |
| child | 13653:e0bbf85edc21 |
comparison
equal
deleted
inserted
replaced
| 13650:9a66b53a5076 | 13651:b9d369f77121 |
|---|---|
| 179 return "rc.d"; | 179 return "rc.d"; |
| 180 end | 180 end |
| 181 end | 181 end |
| 182 | 182 |
| 183 local function service_command_warning(service_command) | 183 local function service_command_warning(service_command) |
| 184 if prosody.installed and configmanager.get("*", "prosodyctl_service_warnings") ~= false then | 184 if true or prosody.installed and configmanager.get("*", "prosodyctl_service_warnings") ~= false then |
| 185 show_warning("WARNING: Use of prosodyctl start/stop/restart/reload is not recommended"); | 185 show_warning("ERROR: Use of 'prosodyctl %s' is disabled in this installation because", service_command); |
| 186 show_warning(" if Prosody is managed by an init system - use that directly instead."); | 186 |
| 187 local init = has_init_system() | 187 local init = has_init_system() |
| 188 if init == "systemd" then | 188 if init then |
| 189 show_warning(" e.g. systemctl %s prosody", service_command); | 189 show_warning(" we detected that this system uses %s for managing services.", init); |
| 190 elseif init == "rc.d" then | 190 show_warning(""); |
| 191 show_warning(" e.g. /etc/init.d/prosody %s", service_command); | 191 show_warning(" To avoid problems, use that directly instead. For example:"); |
| 192 end | 192 show_warning(""); |
| 193 show_warning(""); | 193 if init == "systemd" then |
| 194 show_warning(" systemctl %s prosody", service_command); | |
| 195 elseif init == "rc.d" then | |
| 196 show_warning(" /etc/init.d/prosody %s", service_command); | |
| 197 end | |
| 198 else | |
| 199 show_warning(" it may conflict with your system's service manager."); | |
| 200 show_warning(""); | |
| 201 end | |
| 202 | |
| 203 show_warning(" Proceeding to use prosodyctl may cause process management issues."); | |
| 204 show_warning(" You can pass --force to override this warning, or set"); | |
| 205 show_warning(" prosodyctl_service_warnings = false in your global config."); | |
| 206 | |
| 207 os.exit(1); | |
| 194 end | 208 end |
| 195 end | 209 end |
| 196 | 210 |
| 197 function commands.start(arg) | 211 function commands.start(arg) |
| 198 local opts = parse_args(arg, only_help); | 212 local opts = parse_args(arg, only_help); |
| 199 if opts.help then | 213 if opts.help then |
| 200 show_usage([[start]], [[Start Prosody]]); | 214 show_usage([[start]], [[Start Prosody]]); |
| 201 return 0; | 215 return 0; |
| 202 end | 216 end |
| 203 service_command_warning("start"); | 217 if not opts.force then |
| 218 service_command_warning("start"); | |
| 219 end | |
| 204 local ok, ret = prosodyctl.isrunning(); | 220 local ok, ret = prosodyctl.isrunning(); |
| 205 if not ok then | 221 if not ok then |
| 206 show_message(error_messages[ret]); | 222 show_message(error_messages[ret]); |
| 207 return 1; | 223 return 1; |
| 208 end | 224 end |
| 299 if opts.help then | 315 if opts.help then |
| 300 show_usage([[stop]], [[Stop a running Prosody server]]); | 316 show_usage([[stop]], [[Stop a running Prosody server]]); |
| 301 return 0; | 317 return 0; |
| 302 end | 318 end |
| 303 | 319 |
| 304 service_command_warning("stop"); | 320 if not opts.force then |
| 321 service_command_warning("stop"); | |
| 322 end | |
| 305 | 323 |
| 306 local ok, running = prosodyctl.isrunning(); | 324 local ok, running = prosodyctl.isrunning(); |
| 307 if not ok then | 325 if not ok then |
| 308 show_message(error_messages[running]); | 326 show_message(error_messages[running]); |
| 309 return 1; | 327 return 1; |
| 341 if opts.help then | 359 if opts.help then |
| 342 show_usage([[restart]], [[Restart a running Prosody server]]); | 360 show_usage([[restart]], [[Restart a running Prosody server]]); |
| 343 return 1; | 361 return 1; |
| 344 end | 362 end |
| 345 | 363 |
| 346 service_command_warning("restart"); | 364 if not opts.force then |
| 365 service_command_warning("restart"); | |
| 366 end | |
| 347 | 367 |
| 348 commands.stop(arg); | 368 commands.stop(arg); |
| 349 return commands.start(arg); | 369 return commands.start(arg); |
| 350 end | 370 end |
| 351 | 371 |
| 528 elseif not running then | 548 elseif not running then |
| 529 show_message("Prosody is not running"); | 549 show_message("Prosody is not running"); |
| 530 return 1; | 550 return 1; |
| 531 end | 551 end |
| 532 | 552 |
| 553 if not opts.force then | |
| 554 service_command_warning("reload"); | |
| 555 end | |
| 556 | |
| 533 local ok, ret = prosodyctl.reload(); | 557 local ok, ret = prosodyctl.reload(); |
| 534 if ok then | 558 if ok then |
| 535 | 559 |
| 536 show_message("Prosody log files re-opened and config file reloaded. You may need to reload modules for some changes to take effect."); | 560 show_message("Prosody log files re-opened and config file reloaded. You may need to reload modules for some changes to take effect."); |
| 537 return 0; | 561 return 0; |