-
Notifications
You must be signed in to change notification settings - Fork 87
LCORE-1869: Add graceful teardown and automatic cleanup for llama-stack container #1802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,13 +17,14 @@ LLAMA_STACK_IMAGE ?= lightspeed-llama-stack:local | |
| LLAMA_STACK_PORT ?= 8321 | ||
| CONTAINER_RUNTIME ?= $(shell command -v podman 2>/dev/null || command -v docker 2>/dev/null) | ||
|
|
||
| .PHONY: run run-stack build-llama-stack-image remove-llama-stack-container start-llama-stack-container wait-for-llama-stack-health clean-llama-stack | ||
| .PHONY: run run-stack build-llama-stack-image remove-llama-stack-container stop-llama-stack-container start-llama-stack-container wait-for-llama-stack-health clean-llama-stack | ||
|
|
||
| run-stack: ## Run lightspeed-stack directly, without building dependent service/s | ||
| uv run src/lightspeed_stack.py -c $(CONFIG) | ||
|
|
||
| run: start-llama-stack-container ## Run the service locally with dependent services | ||
| @echo "Starting Lightspeed Core Stack..." | ||
| @trap 'echo ""; echo "Stopping services..."; $(MAKE) stop-llama-stack-container' EXIT INT TERM; \ | ||
| $(MAKE) run-stack | ||
|
Comment on lines
25
to
28
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect Makefile around the cited line ranges with line numbers
if [ -f Makefile ]; then
wc -l Makefile
sed -n '1,220p' Makefile | nl -ba | sed -n '1,220p'
else
echo "Makefile not found at repo root"
fiRepository: lightspeed-core/lightspeed-stack Length of output: 150 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== Makefile line 15-40 =="
awk 'NR>=15 && NR<=40 {printf "%5d\t%s\n", NR, $0}' Makefile
echo "== Makefile line 55-130 =="
awk 'NR>=55 && NR<=130 {printf "%5d\t%s\n", NR, $0}' Makefile
echo "== Makefile line 130-200 =="
awk 'NR>=130 && NR<=200 {printf "%5d\t%s\n", NR, $0}' MakefileRepository: lightspeed-core/lightspeed-stack Length of output: 9588 🏁 Script executed: #!/bin/bash
set -euo pipefail
awk 'NR>=30 && NR<=90 {printf "%5d\t%s\n", NR, $0}' MakefileRepository: lightspeed-core/lightspeed-stack Length of output: 3415 Fix Makefile cleanup: trap doesn’t cover prerequisite startup failures, and shutdown doesn’t remove/save logs
🤖 Prompt for AI Agents |
||
|
|
||
| build-llama-stack-image: remove-llama-stack-container ## Build llama-stack container image | ||
|
|
@@ -34,10 +35,26 @@ build-llama-stack-image: remove-llama-stack-container ## Build llama-stack conta | |
| fi | ||
| $(CONTAINER_RUNTIME) build -f deploy/llama-stack/test.containerfile -t $(LLAMA_STACK_IMAGE) . | ||
|
|
||
| remove-llama-stack-container: ## Remove existing llama-stack container | ||
| stop-llama-stack-container: ## Gracefully stop llama-stack container | ||
| @if [ -n "$(CONTAINER_RUNTIME)" ] && $(CONTAINER_RUNTIME) inspect $(LLAMA_STACK_CONTAINER_NAME) >/dev/null 2>&1; then \ | ||
| echo "Removing existing llama-stack container..."; \ | ||
| echo "Stopping llama-stack container (timeout: 10s)..."; \ | ||
| if $(CONTAINER_RUNTIME) stop -t 10 $(LLAMA_STACK_CONTAINER_NAME) 2>/dev/null; then \ | ||
| echo "✓ Container stopped gracefully"; \ | ||
| else \ | ||
| echo "⚠ Container did not stop gracefully, capturing logs..."; \ | ||
| $(CONTAINER_RUNTIME) logs $(LLAMA_STACK_CONTAINER_NAME) > /tmp/llama-stack-failure.log 2>&1 || true; \ | ||
| echo "Logs saved to /tmp/llama-stack-failure.log"; \ | ||
| $(CONTAINER_RUNTIME) kill $(LLAMA_STACK_CONTAINER_NAME) 2>/dev/null || true; \ | ||
| fi; \ | ||
| fi | ||
|
|
||
| remove-llama-stack-container: ## Remove llama-stack container (saves logs first) | ||
| @if [ -n "$(CONTAINER_RUNTIME)" ] && $(CONTAINER_RUNTIME) inspect $(LLAMA_STACK_CONTAINER_NAME) >/dev/null 2>&1; then \ | ||
| echo "Saving container logs before removal..."; \ | ||
| $(CONTAINER_RUNTIME) logs $(LLAMA_STACK_CONTAINER_NAME) > /tmp/llama-stack-last-run.log 2>&1 || true; \ | ||
| echo "Removing llama-stack container..."; \ | ||
| $(CONTAINER_RUNTIME) rm -f $(LLAMA_STACK_CONTAINER_NAME); \ | ||
| echo "✓ Container removed (logs saved to /tmp/llama-stack-last-run.log)"; \ | ||
| fi | ||
|
|
||
| start-llama-stack-container: build-llama-stack-image ## Start llama-stack container | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make runstill leaves the container behind on the common exit path.Line 27 only invokes
stop-llama-stack-container, but the actual log-preserving cleanup lives inremove-llama-stack-container. After a normal Ctrl+C/EXIT you keep a stoppedlightspeed-llama-stackcontainer around and never write/tmp/llama-stack-last-run.log, which misses the stated automatic cleanup behavior.Also applies to: 51-57
🤖 Prompt for AI Agents