#!/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