This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 98a22410dbe9 CAMEL-26929: camel-jbang - camel stop without a name 
stops none when several integrations run, unless --all (#30027)
98a22410dbe9 is described below

commit 98a22410dbe97aa066681814f179ed03fdc8788c
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 15 19:22:31 2026 +0100

    CAMEL-26929: camel-jbang - camel stop without a name stops none when 
several integrations run, unless --all (#30027)
    
    camel stop without a name stopped every running integration, without asking 
when there is no terminal: during the CLI
    scan one agent's bare camel stop stopped the integrations of the other 
agents. Without a name it now stops the one
    integration that runs, and when two or more run it stops none, lists them 
and exits with 2. --all (or an explicit '*')
    stops them all. Camel 4.0 had removed --all, when camel stop without a name 
became "stop all"; it comes back for this.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc    |  6 ++
 .../modules/ROOT/pages/camel-jbang-managing.adoc   |  5 +-
 .../pages/jbang-commands/camel-jbang-stop.adoc     |  1 +
 .../META-INF/camel-jbang-commands-metadata.json    |  2 +-
 .../jbang/core/commands/process/StopProcess.java   | 36 ++++++++++--
 .../core/commands/process/StopProcessTest.java     | 65 ++++++++++++++++++++++
 .../src/test/resources/golden/cli-help.txt         | 10 +++-
 .../src/test/resources/golden/cli-parse.txt        |  2 +-
 8 files changed, 116 insertions(+), 11 deletions(-)

diff --git 
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 9fc52bd31d2c..b4efb09fd2c6 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -3489,6 +3489,12 @@ The DTOs of `camel generate rest --dto` use Jakarta EE 
(`jakarta.validation`, `j
 Spring (`@DateTimeFormat`). The OpenAPI Generator no longer prints its banner 
on stdout after the REST DSL, and
 `--input` takes an `http://` or `https://` URL.
 
+=== camel-jbang - camel stop without a name
+
+`camel stop` without a name stops the integration that runs, as before, but 
when two or more run it stops none: it
+lists them and exits with `2`. Use `camel stop --all` (or `camel stop '*'`) to 
stop them all, as `camel stop` did. A
+bare `camel stop`, such as of an AI agent, stopped the integrations of the 
user and of other agents too.
+
 === camel-jbang - camel version list
 
 * `camel version list` prints the `Last updated` note on stderr, so stdout has 
the table only.
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-managing.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang-managing.adoc
index 857c05a20a6e..7ecddb10ed19 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-managing.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-managing.adoc
@@ -54,11 +54,12 @@ of the new integration (its output, the warnings and errors 
and what it prints o
 `~/.camel/<pid>-run.log`). When the new integration stops right away, it 
prints the end of the log
 and exits with code `1`; when it is still starting after `--timeout`, it exits 
with code `124` and leaves it running.
 
-Stop all integrations (omit the name):
+Without a name, `camel stop` stops the integration that runs. When several 
run, it stops none and lists them (exit
+code `2`): give the name or PID of the one to stop, or stop them all with 
`--all`:
 
 [source,bash]
 ----
-camel stop
+camel stop --all
 Shutting down Camel integration (PID: 61818)
 Shutting down Camel integration (PID: 62506)
 ----
diff --git 
a/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-stop.adoc 
b/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-stop.adoc
index 557f3b74467d..c80a580ba91b 100644
--- a/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-stop.adoc
+++ b/docs/user-manual/modules/ROOT/pages/jbang-commands/camel-jbang-stop.adoc
@@ -19,6 +19,7 @@ camel stop [options]
 [cols="2,5,1,2",options="header"]
 |===
 | Option | Description | Default | Type
+| `--all` | Stop all running Camel integrations |  | boolean
 | `--kill` | To force killing the process (SIGKILL) |  | boolean
 | `--no-wait` | Do not wait for the integration to stop |  | boolean
 | `--timeout` | How long to wait for the integration to stop, in millis or as 
a duration such as 30s | 60000 | long
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
 
b/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
index 2851cd3ccd97..a94bc7ee1d41 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/generated/resources/META-INF/camel-jbang-commands-metadata.json
@@ -33,7 +33,7 @@
     { "name": "semantic", "fullName": "semantic", "description": "List 
semantic definitions and expert contracts", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.action.CamelSemantic", "options": [ { 
"names": "--expert", "description": "Show the operations and parameter contract 
of this expert", "javaType": "java.lang.String", "type": "string" }, { "names": 
"--json", "description": "Output a single JSON document", "javaType": 
"boolean", "type": "boolean" }, { "names": "--timeou [...]
     { "name": "shell", "fullName": "shell", "description": "Interactive Camel 
CLI shell.", "sourceClass": "org.apache.camel.dsl.jbang.core.commands.Shell", 
"options": [ { "names": "-h,--help", "description": "Display this help and 
exit", "javaType": "boolean", "type": "boolean" } ] },
     { "name": "status", "fullName": "status", "description": "The state of a 
running Camel integration in one call: where it runs and its files, its routes, 
health, last errors and last reload, its JVM, and the end of its log", 
"sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.process.IntegrationStatus", 
"options": [ { "names": "--errors", "description": "How many of the last errors 
to show", "defaultValue": "5", "javaType": "int", "type": "integer" }, { 
"names": "--json", "descri [...]
-    { "name": "stop", "fullName": "stop", "description": "Shuts down running 
Camel integrations", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.process.StopProcess", "options": [ { 
"names": "--kill", "description": "To force killing the process (SIGKILL)", 
"javaType": "boolean", "type": "boolean" }, { "names": "--no-wait", 
"description": "Do not wait for the integration to stop", "javaType": 
"boolean", "type": "boolean" }, { "names": "--timeout", "description": "How 
long to wa [...]
+    { "name": "stop", "fullName": "stop", "description": "Shuts down running 
Camel integrations", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.process.StopProcess", "options": [ { 
"names": "--all", "description": "Stop all running Camel integrations", 
"javaType": "boolean", "type": "boolean" }, { "names": "--kill", "description": 
"To force killing the process (SIGKILL)", "javaType": "boolean", "type": 
"boolean" }, { "names": "--no-wait", "description": "Do not wait for the in 
[...]
     { "name": "top", "fullName": "top", "description": "Top status of Camel 
integrations", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.process.CamelTop", "options": [ { 
"names": "--watch", "description": "Execute periodically and showing output 
fullscreen", "javaType": "boolean", "type": "boolean" }, { "names": 
"-h,--help", "description": "Display this help and exit", "javaType": 
"boolean", "type": "boolean" } ], "subcommands": [ { "name": "context", 
"fullName": "top context [...]
     { "name": "trace", "fullName": "trace", "description": "Tail message 
traces from running Camel integrations", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.action.CamelTraceAction", "options": 
[ { "names": "--action", "description": "Action to start, stop, clear, list 
status, or dump traces", "defaultValue": "status", "javaType": 
"java.lang.String", "type": "string" }, { "names": "--ago", "description": "Use 
ago instead of yyyy-MM-dd HH:mm:ss in timestamp.", "javaType": "b [...]
     { "name": "transform", "fullName": "transform", "description": "Transform 
message or Camel routes", "sourceClass": 
"org.apache.camel.dsl.jbang.core.commands.TransformCommand", "options": [ { 
"names": "-h,--help", "description": "Display this help and exit", "javaType": 
"boolean", "type": "boolean" } ], "subcommands": [ { "name": "dataweave", 
"fullName": "transform dataweave", "description": "Convert DataWeave scripts to 
DataSonnet format", "sourceClass": "org.apache.camel.dsl.jbang.c [...]
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/StopProcess.java
 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/StopProcess.java
index b34868a5712e..f1954e45bd42 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/StopProcess.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/StopProcess.java
@@ -33,6 +33,7 @@ import 
org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
 import org.apache.camel.dsl.jbang.core.common.BackgroundLog;
 import org.apache.camel.dsl.jbang.core.common.CliException;
 import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
+import org.apache.camel.dsl.jbang.core.common.ProcessFinder;
 import org.apache.camel.dsl.jbang.core.common.TimeoutConverter;
 import org.apache.camel.dsl.jbang.run.common.PathUtils;
 import org.apache.camel.util.TimeUtils;
@@ -41,14 +42,18 @@ import org.apache.camel.util.TimeUtils;
                    footer = {
                            "Examples:",
                            "  camel stop hello",
-                           "  camel stop *",
+                           "  camel stop --all",
                            "  camel stop 12345",
                            "  camel stop hello --timeout=2m",
                            "  camel stop hello --kill" })
 public class StopProcess extends ProcessBaseCommand {
 
-    @Argument(description = "Name or pid of running Camel integration(s)")
-    String name = "*";
+    @Argument(description = "Name or pid of running Camel integration(s). 
Without a name, the one integration that runs"
+                            + " (use --all when several run)")
+    String name;
+
+    @Option(name = "all", hasValue = false, description = "Stop all running 
Camel integrations")
+    boolean all;
 
     @Option(name = "kill", hasValue = false, description = "To force killing 
the process (SIGKILL)")
     boolean kill;
@@ -67,7 +72,13 @@ public class StopProcess extends ProcessBaseCommand {
 
     @Override
     public Integer doCall() throws Exception {
-        List<Long> pids = findIntegrationPids(name);
+        if (all && name != null && !name.isBlank()) {
+            throw CliException.usage("Give the name or pid of the integration 
to stop, or --all, not both");
+        }
+        if (!all && (name == null || name.isBlank())) {
+            requireOneRunning();
+        }
+        List<Long> pids = findIntegrationPids(all ? "*" : name);
 
         for (Long pid : pids) {
             Path pidFile = 
CommandLineHelper.getCamelDir().resolve(Long.toString(pid));
@@ -111,6 +122,23 @@ public class StopProcess extends ProcessBaseCommand {
         return 0;
     }
 
+    /**
+     * Without a name and without --all, camel stop stops the one integration 
that runs. When several run it stops none:
+     * a bare camel stop, such as of an AI agent, stopped the integrations of 
the user and of other agents too
+     * (CAMEL-26929).
+     *
+     * @throws CliException with exit code 2 when more than one integration 
runs
+     */
+    private void requireOneRunning() {
+        List<ProcessFinder.CamelProcess> running = ProcessFinder.find("*");
+        if (running.size() > 1) {
+            String names = running.stream().map(p -> p.name() + " (PID: " + 
p.pid() + ")")
+                    .collect(Collectors.joining(", "));
+            throw CliException.usage(running.size() + " Camel integrations are 
running: " + names
+                                     + ". Give the name or pid of the one to 
stop, or --all to stop them all");
+        }
+    }
+
     /**
      * Waits until the process has exited.
      *
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/StopProcessTest.java
 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/StopProcessTest.java
index f0c348f0b2ad..9650a5c4b67d 100644
--- 
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/StopProcessTest.java
+++ 
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/process/StopProcessTest.java
@@ -185,4 +185,69 @@ class StopProcessTest extends ProcessCommandTestSupport {
             assertEquals("", printer.getOutput().trim(), "No output expected 
when no processes match");
         }
     }
+
+    @Test
+    void testStopWithoutNameWhenSeveralRunStopsNone() throws Exception {
+        // CAMEL-26929: a bare camel stop stopped every integration, also 
those of the user and of other agents
+        Path orders = running(TEST_PID, "orders");
+        Path billing = running(TEST_PID + 1, "billing");
+        StopProcess command = new StopProcess(new 
CamelJBangMain().withPrinter(printer));
+
+        try (MockedStatic<ProcessHandle> mocked = 
mockStatic(ProcessHandle.class)) {
+            mockRunning(mocked);
+
+            CliException e = assertThrows(CliException.class, command::doCall);
+
+            assertEquals(CliExitCode.USAGE, e.getExitCode());
+            assertEquals("2 Camel integrations are running: orders (PID: 
12345), billing (PID: 12346)."
+                         + " Give the name or pid of the one to stop, or --all 
to stop them all",
+                    e.getMessage());
+            assertTrue(Files.exists(orders), "orders keeps running");
+            assertTrue(Files.exists(billing), "billing keeps running");
+        }
+    }
+
+    @Test
+    void testStopAll() throws Exception {
+        Path orders = running(TEST_PID, "orders");
+        Path billing = running(TEST_PID + 1, "billing");
+        StopProcess command = new StopProcess(new 
CamelJBangMain().withPrinter(printer));
+        command.all = true;
+
+        try (MockedStatic<ProcessHandle> mocked = 
mockStatic(ProcessHandle.class)) {
+            mockRunning(mocked);
+
+            assertEquals(0, command.doCall());
+
+            assertFalse(Files.exists(orders), "orders is stopped");
+            assertFalse(Files.exists(billing), "billing is stopped");
+        }
+    }
+
+    @Test
+    void testStopAllWithANameIsAUsageError() {
+        StopProcess command = new StopProcess(new 
CamelJBangMain().withPrinter(printer));
+        command.all = true;
+        command.name = "orders";
+
+        CliException e = assertThrows(CliException.class, command::doCall);
+
+        assertEquals(CliExitCode.USAGE, e.getExitCode());
+    }
+
+    // an integration that runs: its status file and its pid file, which camel 
stop deletes
+    private static Path running(long pid, String name) throws Exception {
+        writeStatusFile(pid, buildContextStatus(name, 5));
+        Path pidFile = 
CommandLineHelper.getCamelDir().resolve(Long.toString(pid));
+        Files.writeString(pidFile, "");
+        return pidFile;
+    }
+
+    private static void mockRunning(MockedStatic<ProcessHandle> mocked) {
+        ProcessHandle first = mockProcessHandle(TEST_PID);
+        ProcessHandle second = mockProcessHandle(TEST_PID + 1);
+        ProcessHandle current = mockCurrentHandle();
+        mocked.when(ProcessHandle::current).thenReturn(current);
+        mocked.when(ProcessHandle::allProcesses).thenAnswer(inv -> 
Stream.of(first, second));
+    }
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/cli-help.txt 
b/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/cli-help.txt
index 2117d969dbe8..293905978d1e 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/cli-help.txt
+++ b/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/cli-help.txt
@@ -6227,20 +6227,24 @@ Examples:
 
 == camel stop --help
 Shuts down running Camel integrations
-Usage: camel stop [-h] [--kill] [--timeout=<timeout>] [--no-wait] [<name>]
+Usage: camel stop [-h] [--all] [--kill] [--timeout=<timeout>] [--no-wait]
+                   [<name>]
 
 Options:
   -h, --help               Display this help and exit
+      --all                Stop all running Camel integrations
       --kill               To force killing the process (SIGKILL)
       --timeout=<timeout>  How long to wait for the integration to stop, in
                            millis or as a duration such as 30s
                            Default: 60000
       --no-wait            Do not wait for the integration to stop
-  <name>                   Name or pid of running Camel integration(s)
+  <name>                   Name or pid of running Camel integration(s). Without
+                           a name, the one integration that runs (use --all 
when
+                           several run)
 
 Examples:
   camel stop hello
-  camel stop *
+  camel stop --all
   camel stop 12345
   camel stop hello --timeout=2m
   camel stop hello --kill
diff --git 
a/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/cli-parse.txt 
b/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/cli-parse.txt
index 519c1c88e139..08cc3091a7a4 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/cli-parse.txt
+++ b/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/cli-parse.txt
@@ -5408,7 +5408,7 @@
 > shell
 > stop
   kill=false
-  name="*"
+  name=null
   noWait=false
   timeout=60000
 > stop --kill

Reply via email to