From 895a08584683f3c60b47456f8df5e1a86e28cb41 Mon Sep 17 00:00:00 2001 From: krtr Date: Thu, 4 Dec 2025 17:16:48 +0100 Subject: [PATCH] Creates Qdrant pod --- bin/create_pod_qdrant.sh | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100755 bin/create_pod_qdrant.sh diff --git a/bin/create_pod_qdrant.sh b/bin/create_pod_qdrant.sh new file mode 100755 index 0000000..f0cbd82 --- /dev/null +++ b/bin/create_pod_qdrant.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +# To be run by user krtr to create the pod and container with qdrant + +set -e + +# Environment variables +POD_NAME='qdrant_pod' +CTR_NAME='qdrant_ctr' +CTR_IMAGE='docker.io/qdrant/qdrant:v1.16' +HOST_LOCAL_IP='127.0.0.1' +HOST_PORT_REST='8088' +CONTAINER_PORT_REST='6333' +HOST_PORT_GRPC='8089' +CONTAINER_PORT_GRPC='6334' +BIND_DIR="$HOME/.local/share/$POD_NAME" +# Container /home/node/.n8n holds workflows, credentials, config +DATA_DIR="$BIND_DIR/data" +USER_SYSTEMD_DIR="$HOME/.config/systemd/user" + +# Prepare directories +mkdir -p "$DATA_DIR" "$USER_SYSTEMD_DIR" + +# Create pod if not yet existing +if ! podman pod exists "$POD_NAME"; then + podman pod create -n "$POD_NAME" \ + -p "$HOST_LOCAL_IP:$HOST_PORT_REST:$CONTAINER_PORT_REST" \ + -p "$HOST_LOCAL_IP:$HOST_PORT_GRPC:$CONTAINER_PORT_GRPC" + echo "Pod '$POD_NAME' created (rc=$?)" +else + echo "Pod '$POD_NAME' already exists." +fi + +# Remove any old container +podman rm -f "$CTR_NAME" +# New Container +podman run -d --name "$CTR_NAME" --pod "$POD_NAME" \ + -v "$DATA_DIR:/qdrant/storage:Z" \ + "$CTR_IMAGE" +echo "Container '$CTR_NAME' started (rc=$?)" + +# Generate systemd service files +cd "$USER_SYSTEMD_DIR" +podman generate systemd --name --new --files "$POD_NAME" +echo "Generated systemd service files (rc=$?)" + +# Stop & remove live pod and containers +podman pod stop --ignore --time 15 "$POD_NAME" +podman pod rm -f --ignore "$POD_NAME" +if podman pod exists "$POD_NAME"; then + echo "ERROR: Pod $POD_NAME still exists." >&2 + exit 1 +else + echo "Stopped & removed live pod $POD_NAME and containers." +fi + +# Enable systemd user services +systemctl --user daemon-reload +# pod service (creates pod + containers) +systemctl --user enable --now "pod-${POD_NAME}.service" +systemctl --user is-enabled "pod-${POD_NAME}.service" +systemctl --user is-active "pod-${POD_NAME}.service" +echo "Enabled systemd service pod-${POD_NAME}.service (rc=$?)" +echo "To view status: systemctl --user status pod-${POD_NAME}.service" +echo "To view logs: journalctl --user -u pod-${POD_NAME}.service -f" + +# Optional: also manage containers individually (generated by podman generate systemd) +# systemctl --user enable --now "container-${CTR_NAME}.service" +# systemctl --user enable --now "container-${RUNNERS_CTR_NAME}.service" +# echo "To view n8n logs : journalctl --user -u container-${CTR_NAME}.service -f" +# echo "To view runners logs : journalctl --user -u container-${RUNNERS_CTR_NAME}.service -f" + +# Wait for API readiness (/health) +CHECK_URL="http://$HOST_LOCAL_IP:$HOST_PORT_REST" +# echo -n "Waiting for Qdrant API at $CHECK_URL ..." +for attempt in $(seq 1 30); do + if curl -fsS "$CHECK_URL" >/dev/null 2>&1; then + echo "Qdrant REST API is reachable at http://$HOST_LOCAL_IP:$HOST_PORT_REST." + echo "Qdrant GRPC API is reachable at http://$HOST_LOCAL_IP:$HOST_PORT_GRPC." + break + fi + sleep 2 + if [ "$attempt" -eq 30 ]; then + echo "timeout error." >&2 + exit 1 + fi +done