start_clip_service.sh 1.53 KB
#!/bin/bash
#
# Start CLIP vector service (clip-server) in an independent environment.
#
# This service is designed to be a drop-in alternative to the local
# `embeddings` service, but runs in its own Python environment and depends
# on `jina` via `clip-server`.
#
set -e

cd "$(dirname "$0")/.."

LOG_DIR="$(pwd)/logs"
mkdir -p "${LOG_DIR}"
PID_FILE="${LOG_DIR}/clip_service.pid"
LOG_FILE="${LOG_DIR}/clip_service.log"

echo "========================================"
echo "Starting CLIP vector service (clip-server)"
echo "========================================"

# Force isolated CN-CLIP runtime env
CLIP_VENV="$(pwd)/.venv-cnclip"
if [ ! -x "${CLIP_VENV}/bin/python" ]; then
  echo "Error: isolated clip runtime not found: ${CLIP_VENV}" >&2
  echo "Please run: ./scripts/setup_cnclip_venv.sh" >&2
  exit 1
fi
PYTHON_BIN="${CLIP_VENV}/bin/python"

if [ -f "${PID_FILE}" ]; then
  EXISTING_PID="$(cat "${PID_FILE}")"
  if ps -p "${EXISTING_PID}" > /dev/null 2>&1; then
    echo "clip-server already appears to be running with PID ${EXISTING_PID}."
    echo "If this is incorrect, remove ${PID_FILE} and try again."
    exit 0
  else
    echo "Stale PID file found at ${PID_FILE}, removing..."
    rm -f "${PID_FILE}"
  fi
fi

echo "Log file: ${LOG_FILE}"
echo "PID file: ${PID_FILE}"
echo
echo "Starting clip-server in background..."

nohup "${PYTHON_BIN}" -m clip_server > "${LOG_FILE}" 2>&1 &
SERVICE_PID=$!
echo "${SERVICE_PID}" > "${PID_FILE}"

echo "clip-server started with PID ${SERVICE_PID}."
echo "You can check logs with:"
echo "  tail -f ${LOG_FILE}"