Files
DesTEngSsv006_swd/kischdle/llmux/scripts/create_pod_llmux.sh
2026-04-05 13:05:38 +02:00

88 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# Create the llmux Podman pod and systemd service.
# Run as user llm: bash scripts/create_pod_llmux.sh
set -euo pipefail
POD_NAME="llmux_pod"
CTR_NAME="llmux_ctr"
IMAGE="localhost/llmux:latest"
PORT="127.0.0.1:8081:8081"
BIND_DIR="$HOME/.local/share/${POD_NAME}"
USER_SYSTEMD_DIR="$HOME/.config/systemd/user"
MODELS_DIR="${BIND_DIR}/models"
CONFIG_DIR="${BIND_DIR}/config"
if [ ! -d "$MODELS_DIR" ]; then
echo "ERROR: Models directory not found: $MODELS_DIR"
echo "Run download_models.sh first."
exit 1
fi
if [ ! -f "$CONFIG_DIR/models.yaml" ]; then
echo "ERROR: Config not found: $CONFIG_DIR/models.yaml"
exit 1
fi
if [ ! -f "$CONFIG_DIR/api_keys.yaml" ]; then
echo "ERROR: Config not found: $CONFIG_DIR/api_keys.yaml"
exit 1
fi
mkdir -p "$USER_SYSTEMD_DIR"
LLMUX_SRC="${LLMUX_SRC:-/home/tlg/swd/kischdle/llmux}"
if ! podman image exists "$IMAGE"; then
echo "Building container image from $LLMUX_SRC ..."
if [ ! -f "$LLMUX_SRC/Dockerfile" ]; then
echo "ERROR: Dockerfile not found at $LLMUX_SRC/Dockerfile"
echo "Set LLMUX_SRC to the llmux source directory."
exit 1
fi
podman build -t llmux:latest -f "$LLMUX_SRC/Dockerfile" "$LLMUX_SRC"
fi
podman pod exists "$POD_NAME" && podman pod stop "$POD_NAME" 2>/dev/null || true
podman pod exists "$POD_NAME" && podman pod rm -f "$POD_NAME" 2>/dev/null || true
echo "Creating pod $POD_NAME..."
podman pod create --name "$POD_NAME" -p "$PORT"
echo "Creating container $CTR_NAME..."
podman run -d \
--name "$CTR_NAME" \
--pod "$POD_NAME" \
--device nvidia.com/gpu=all \
-v "${MODELS_DIR}:/models:ro" \
-v "${CONFIG_DIR}:/config:ro" \
-e LLMUX_CONFIG_DIR=/config \
-e LLMUX_MODELS_DIR=/models \
"$IMAGE"
echo "Waiting for llmux to start..."
for i in $(seq 1 30); do
if curl -sf http://127.0.0.1:8081/health > /dev/null 2>&1; then
echo "llmux is healthy!"
break
fi
sleep 2
done
echo "Generating systemd units..."
cd "$USER_SYSTEMD_DIR"
podman generate systemd --files --new --name "$POD_NAME"
podman pod stop "$POD_NAME"
podman pod rm -f "$POD_NAME"
systemctl --user daemon-reload
systemctl --user enable --now "pod-${POD_NAME}.service"
echo ""
echo "=== llmux pod created and enabled ==="
echo "Service: systemctl --user status pod-${POD_NAME}.service"
echo "Health: curl http://127.0.0.1:8081/health"
echo "Logs: journalctl --user -u pod-${POD_NAME}.service -f"