davsclaus opened a new pull request, #30123:
URL: https://github.com/apache/camel/pull/30123

   ## What
   
   `camel infra run --background` (and `camel infra restart --background`) 
waits for the service to start and says what happened, as `camel run 
--background` does since 4.24.
   
   Before, the child started with its output in a pipe that nobody read, and 
the command returned `0` right away. A service that could not start was gone 
without a word: Docker down, a container name that is taken, a bad image. 
`camel infra ps` then showed nothing.
   
   ## How
   
   - The output of the service goes to `~/.camel/<pid>-run.log` 
(`BackgroundLog.start`, as for `camel run --background`).
   - The command waits until the service has written its pid file 
`infra-<service>-<pid>.json`, which `infra run` writes once `initialize()` has 
returned:
     - **started**: prints its connection details, as a foreground run does, 
plus `Log: <path>`. With `--json` they go in `serviceData`, as in `camel infra 
get --json`, next to `pid`, `alias` and `log`. Exit `0`.
     - **ended before it started**: prints `Service kafka (PID: n) did not 
start (exit code n)` and its output (on stderr with `--json`), then exits with 
its exit code (`1` when that was `0`).
     - **still starting after the wait**, such as while it pulls its image the 
first time: left running, exit `124`, with the log path.
   - `--background-wait` works as in `camel run` (60 s by default, `2m`, 
`false` to return right away), also on `camel infra restart`. For that, 
`BackgroundWait` is now public.
   - Cleanup: the service removes its run log when it stops. `infra stop 
--kill`, `infra restart --kill` and the pruning of stale pid files remove it as 
well.
   - Docs: a "Running in the background" section on the Dev Services page, and 
an upgrade-guide entry, because `--background` now waits.
   
   This is item 5 of CAMEL-27004 (split from CAMEL-26914). Item 6 (`camel 
debug`) is #30122.
   
   ## Tests
   
   - `InfraRunBackgroundTest` (8 tests) uses a `sh` child in place of the 
service, which writes the pid file as `infra run` does. It covers:
     - started, in text and in JSON
     - fails with its exit code, with the reason on stdout, or on stderr with 
`--json`
     - ends with `0` before it started
     - still starting (exit `124`, left running)
     - no wait
     - the run log is pruned for a service that is gone
   - The help golden file is updated, and the command docs and metadata are 
regenerated.
   - The full `camel-jbang-core` suite passes (3086 + 269 tests).
   - Tried by hand with a launcher built from this branch, in a separate home:
     - `camel infra run kafka --background` started Kafka and printed its 
connection details.
     - A second one failed on the taken container name: exit `70`, with the 
reason printed (before: exit `0` and nothing).
     - `camel infra stop kafka` removed the run log, the pid file and the 
container.
   
   The reason in that second case is a stack trace (`ConflictException: The 
container name "/camel-kafka" is already in use`). That's how `infra run` 
reports this conflict in the foreground too, and turning it into one line like 
the port-in-use message is not part of this PR.
   
   _Claude Code on behalf of Claus Ibsen (davsclaus)_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to