Files
dropshell-templates/llamacpp-monitor/start.sh
j fca9167883
All checks were successful
Test and Publish Templates / test-and-publish (push) Successful in 9s
Add GPU passthrough and host networking to llamacpp-monitor
2026-03-15 15:57:22 +13:00

44 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
source "${AGENT_PATH}/common.sh"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
_check_required_env_vars "CONTAINER_NAME" "LLAMA_SERVER_URL" "MONITOR_PORT" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
# Build GPU device mounts if nvidia-smi is available on the host
GPU_ARGS=""
if command -v nvidia-smi &>/dev/null; then
GPU_ARGS="--device /dev/nvidia0:/dev/nvidia0 \
--device /dev/nvidiactl:/dev/nvidiactl \
--device /dev/nvidia-uvm:/dev/nvidia-uvm \
-v /usr/bin/nvidia-smi:/usr/bin/nvidia-smi:ro \
-v /usr/lib/nvidia:/usr/lib/nvidia:ro \
-e LD_LIBRARY_PATH=/usr/lib/nvidia"
fi
DOCKER_RUN_CMD="docker run -d \
--restart unless-stopped \
--name ${CONTAINER_NAME} \
--network host \
${GPU_ARGS} \
-e LLAMA_SERVER_URL=${LLAMA_SERVER_URL} \
-e MONITOR_PORT=${MONITOR_PORT} \
-v ${SCRIPT_DIR}/monitor.py:/app/monitor.py:ro \
${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG} \
python3 /app/monitor.py"
echo "Starting container ${CONTAINER_NAME}..."
if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then
if _is_container_exists $CONTAINER_NAME; then
echo "Attempting to get logs from failed container..."
_get_container_logs $CONTAINER_NAME
fi
_die "Failed to start container ${CONTAINER_NAME}"
fi
if ! _is_container_running "$CONTAINER_NAME"; then
_get_container_logs $CONTAINER_NAME
_die "Container ${CONTAINER_NAME} is not running after start attempt"
fi
echo "Service ${CONTAINER_NAME} started on port ${MONITOR_PORT}."