Blame view

scripts/start_clip_service.sh 1.84 KB
bad3b18b   tangwang   fix facet for 172
1
2
3
4
5
6
7
8
9
10
11
12
  #!/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")/.."
  
a7920e17   tangwang   项目名称和部署路径修改
13
  LOG_DIR="$(pwd)/logs"
bad3b18b   tangwang   fix facet for 172
14
15
16
17
18
19
20
21
22
  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 "========================================"
  
  # Load conda and activate dedicated environment, if available
a7920e17   tangwang   项目名称和部署路径修改
23
24
  CONDA_ROOT="${CONDA_ROOT:-/home/tw/miniconda3}"
  if [ -f "$CONDA_ROOT/etc/profile.d/conda.sh" ]; then
bad3b18b   tangwang   fix facet for 172
25
    # shellcheck disable=SC1091
a7920e17   tangwang   项目名称和部署路径修改
26
    source "$CONDA_ROOT/etc/profile.d/conda.sh"
bad3b18b   tangwang   fix facet for 172
27
28
29
30
31
32
    conda activate clip_service || {
      echo "Failed to activate conda env 'clip_service'. Please create it first." >&2
      echo "See CLIP_SERVICE_README.md for setup instructions." >&2
      exit 1
    }
  else
a7920e17   tangwang   项目名称和部署路径修改
33
    echo "Warning: $CONDA_ROOT/etc/profile.d/conda.sh not found." >&2
bad3b18b   tangwang   fix facet for 172
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    echo "Please activate the 'clip_service' environment manually before running this script." >&2
  fi
  
  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 -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}"