@@ -17,10 +17,11 @@ LLAMA_STACK_IMAGE ?= lightspeed-llama-stack:local
1717LLAMA_STACK_PORT ?= 8321
1818CONTAINER_RUNTIME ?= $(shell command -v podman 2>/dev/null || command -v docker 2>/dev/null)
1919
20- .PHONY : run build-llama-stack-image remove-llama-stack-container start-llama-stack-container wait-for-llama-stack-health clean-llama-stack
20+ .PHONY : run build-llama-stack-image remove-llama-stack-container stop-llama-stack-container start-llama-stack-container wait-for-llama-stack-health clean-llama-stack
2121
2222run : start-llama-stack-container # # Run the service locally with llama-stack container
2323 @echo " Starting Lightspeed Core Stack..."
24+ @trap ' echo ""; echo "Stopping services..."; $(MAKE) stop-llama-stack-container' EXIT INT TERM; \
2425 uv run src/lightspeed_stack.py -c $(CONFIG )
2526
2627build-llama-stack-image : remove-llama-stack-container # # Build llama-stack container image
@@ -31,10 +32,26 @@ build-llama-stack-image: remove-llama-stack-container ## Build llama-stack conta
3132 fi
3233 $(CONTAINER_RUNTIME ) build -f deploy/llama-stack/test.containerfile -t $(LLAMA_STACK_IMAGE ) .
3334
34- remove -llama-stack-container : # # Remove existing llama-stack container
35+ stop -llama-stack-container : # # Gracefully stop llama-stack container
3536 @if [ -n " $( CONTAINER_RUNTIME) " ] && $(CONTAINER_RUNTIME ) inspect $(LLAMA_STACK_CONTAINER_NAME ) > /dev/null 2>&1 ; then \
36- echo " Removing existing llama-stack container..." ; \
37+ echo " Stopping llama-stack container (timeout: 10s)..." ; \
38+ if $( CONTAINER_RUNTIME) stop -t 10 $( LLAMA_STACK_CONTAINER_NAME) 2> /dev/null; then \
39+ echo " ✓ Container stopped gracefully" ; \
40+ else \
41+ echo " ⚠ Container did not stop gracefully, capturing logs..." ; \
42+ $(CONTAINER_RUNTIME ) logs --tail 100 $(LLAMA_STACK_CONTAINER_NAME ) > /tmp/llama-stack-failure.log 2>&1 || true ; \
43+ echo " Logs saved to /tmp/llama-stack-failure.log" ; \
44+ $(CONTAINER_RUNTIME ) kill $(LLAMA_STACK_CONTAINER_NAME ) 2> /dev/null || true ; \
45+ fi ; \
46+ fi
47+
48+ remove-llama-stack-container : # # Remove llama-stack container (saves logs first)
49+ @if [ -n " $( CONTAINER_RUNTIME) " ] && $(CONTAINER_RUNTIME ) inspect $(LLAMA_STACK_CONTAINER_NAME ) > /dev/null 2>&1 ; then \
50+ echo " Saving container logs before removal..." ; \
51+ $(CONTAINER_RUNTIME ) logs $(LLAMA_STACK_CONTAINER_NAME ) > /tmp/llama-stack-last-run.log 2>&1 || true ; \
52+ echo " Removing llama-stack container..." ; \
3753 $(CONTAINER_RUNTIME ) rm -f $(LLAMA_STACK_CONTAINER_NAME ) ; \
54+ echo " ✓ Container removed (logs saved to /tmp/llama-stack-last-run.log)" ; \
3855 fi
3956
4057start-llama-stack-container : build-llama-stack-image # # Start llama-stack container
0 commit comments