github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/deploy/dev/local/deploy.sh (about)

     1  #!/bin/bash
     2  
     3  ############################################
     4  #
     5  # Usage: deploy.sh
     6  #
     7  # To deploy AIStore as a next tier cluster to the *already running*
     8  # AIStore cluster set DEPLOY_AS_NEXT_TIER=1.
     9  #
    10  # NOTE: system environment variables are listed in the `env` package.
    11  # See https://github.com/NVIDIA/aistore/blob/main/api/env/README.md
    12  #
    13  # NOTE: by default, configuration files are stored under $HOME/.config/ais/<app-name>
    14  # E.g., $HOME/.config/ais/authn - AuthN config, $HOME/.config/ais/cli - CLI config
    15  # and so on. This rule holds for all AIS "applications" except `aisnode` itself.
    16  # See https://github.com/NVIDIA/aistore/tree/main/cmn/fname for the most updated locations.
    17  #
    18  ############################################
    19  
    20  if ! command -v go &> /dev/null; then
    21    echo "Go (toolchain) is not installed"
    22    echo "Use https://go.dev/dl to install the required (as per go.mod) version of Go"
    23    echo "See https://aiatscale.org/docs/getting-started for step-by-step instruction"
    24    exit 1
    25  fi
    26  
    27  if [[ -z $GOPATH ]]; then
    28    echo "Warning: GOPATH variable is not defined, using home directory ${HOME}"
    29    echo "(Tip: see https://aiatscale.org/docs/getting-started for step-by-step instruction)"
    30    echo ""
    31    if [ ! -d "${HOME}/go/pkg" ]; then
    32      echo "${HOME}/go/pkg does not exist (deploying the very first time and from scratch?)"
    33      echo "(Tip: run 'make mod-tidy' to download required packages)"
    34      mkdir -p "${HOME}/go/pkg"
    35      echo ""
    36    fi
    37    if [ ! -w "${HOME}/go/pkg" ]; then
    38      echo "${HOME}/go/pkg is not writable - exiting"
    39      exit 1
    40    fi
    41  else
    42    if [ ! -d "${GOPATH}/pkg" ]; then
    43      echo "${GOPATH}/pkg does not exist (deploying the very first time and from scratch?)"
    44      echo "(Tip: run 'make mod-tidy' to download required packages)"
    45      mkdir -p "${GOPATH}/pkg"
    46      echo ""
    47    fi
    48    if [ ! -w "${GOPATH}/pkg" ]; then
    49      echo "${GOPATH}/pkg is not writable - exiting"
    50      exit 1
    51    fi
    52  fi
    53  
    54  ## NOTE: absolute path to aistore root
    55  ## (should we use `git rev-parse --show-toplevel` instead?)
    56  AISTORE_PATH=$(cd "$(dirname "$0")/../../../"; pwd -P)
    57  source $AISTORE_PATH/deploy/dev/utils.sh
    58  
    59  AIS_USE_HTTPS=${AIS_USE_HTTPS:-false}
    60  AIS_HTTP_CHUNKED_TRANSFER=true
    61  HTTP_WRITE_BUFFER_SIZE=65536
    62  HTTP_READ_BUFFER_SIZE=65536
    63  if [[ -z $DEPLOY_AS_NEXT_TIER ]]; then
    64    PORT=${PORT:-8080}
    65    PORT_INTRA_CONTROL=${PORT_INTRA_CONTROL:-9080}
    66    PORT_INTRA_DATA=${PORT_INTRA_DATA:-10080}
    67    NEXT_TIER=
    68  else
    69    PORT=${PORT:-11080}
    70    PORT_INTRA_CONTROL=${PORT_INTRA_CONTROL:-12080}
    71    PORT_INTRA_DATA=${PORT_INTRA_DATA:-13080}
    72    NEXT_TIER="_next"
    73  fi
    74  PRIMARY_HOST=${AIS_PRIMARY_HOST:-localhost}
    75  AIS_PRIMARY_URL="http://$PRIMARY_HOST:$PORT"
    76  if $AIS_USE_HTTPS; then
    77    AIS_PRIMARY_URL="https://$PRIMARY_HOST:$PORT"
    78  fi
    79  LOG_ROOT="${LOG_ROOT:-/tmp/ais}${NEXT_TIER}"
    80  #### Authentication setup #########
    81  AIS_SECRET_KEY="${AIS_SECRET_KEY:-aBitLongSecretKey}"
    82  AIS_AUTHN_ENABLED="${AIS_AUTHN_ENABLED:-false}"
    83  AIS_AUTHN_SU_NAME="${AIS_AUTHN_SU_NAME:-admin}"
    84  AIS_AUTHN_SU_PASS="${AIS_AUTHN_SU_PASS:-admin}"
    85  ###################################
    86  #
    87  # fspaths config is used if and only if test_fspaths.count == 0
    88  # existence of each fspath is checked at runtime
    89  #
    90  ###################################
    91  
    92  # NOTE:
    93  # for system-wide conventions on locations of these and other configs,
    94  # see: `cmn/fname`
    95  AIS_CONF_DIR="$HOME/.ais$NEXT_TIER"
    96  APP_CONF_DIR="$HOME/.config/ais"
    97  mkdir -p $AIS_CONF_DIR
    98  mkdir -p $APP_CONF_DIR
    99  COLLECTD_CONF_FILE="${APP_CONF_DIR}/collectd.conf"
   100  STATSD_CONF_FILE="${APP_CONF_DIR}/statsd.conf"
   101  
   102  
   103  TEST_FSPATH_COUNT=1
   104  
   105  if lsof -Pi :$PORT -sTCP:LISTEN -t >/dev/null; then
   106    exit_error "TCP port $PORT is not open (check if AIStore is already running)"
   107  fi
   108  TMPF=$(mktemp /tmp/ais$NEXT_TIER.XXXXXXXXX)
   109  touch $TMPF;
   110  OS=$(uname -s)
   111  case $OS in
   112    Linux) # Linux
   113      is_command_available "iostat" "-V"
   114      is_command_available "lsblk" "--version"
   115      is_command_available "df" "--version"
   116      setfattr -n user.comment -v comment $TMPF
   117      ;;
   118    Darwin) # macOS
   119      is_command_available "df" "--version"
   120      xattr -w user.comment comment $TMPF
   121      echo "WARNING: Darwin architecture is not yet fully supported. You may stumble upon bugs and issues when testing on Mac."
   122      ;;
   123    *)
   124      rm $TMPF 2>/dev/null
   125      exit_error "'${OS}' is not supported"
   126      ;;
   127  esac
   128  if [ $? -ne 0 ]; then
   129    rm $TMPF 2>/dev/null
   130    exit_error "bad kernel configuration: extended attributes are not enabled"
   131  fi
   132  rm $TMPF 2>/dev/null
   133  
   134  # Read target count
   135  echo "Enter number of storage targets:"
   136  read -r TARGET_CNT
   137  is_number ${TARGET_CNT}
   138  
   139  # Read proxy count
   140  echo "Enter number of proxies (gateways):"
   141  read -r PROXY_CNT
   142  is_number ${PROXY_CNT}
   143  if  [[ ${PROXY_CNT} -lt 1 && -z "${AIS_PRIMARY_HOST}" ]] ; then
   144    exit_error "Number of proxies must be at least 1 if no external primary proxy is specified with AIS_PRIMARY_HOST. Received "${PROXY_CNT}""
   145  fi
   146  if [[ ${PROXY_CNT} -gt 1 ]] ; then
   147    AIS_DISCOVERY_PORT=$((PORT + 1))
   148    AIS_DISCOVERY_URL="http://$PRIMARY_HOST:$AIS_DISCOVERY_PORT"
   149    if $AIS_USE_HTTPS; then
   150      AIS_DISCOVERY_URL="https://$PRIMARY_HOST:$AIS_DISCOVERY_PORT"
   151    fi
   152  fi
   153  
   154  START=0
   155  END=$((TARGET_CNT + PROXY_CNT - 1))
   156  
   157  echo "Number of local mountpaths (enter 0 for preconfigured filesystems):"
   158  read test_fspath_cnt
   159  is_number ${test_fspath_cnt}
   160  TEST_FSPATH_COUNT=${test_fspath_cnt}
   161  
   162  TEST_LOOPBACK_COUNT=0
   163  
   164  # If not specified, AIS_BACKEND_PROVIDERS will remain empty (or `0`) and
   165  # aisnode build will include neither AWS ("aws") nor GCP ("gcp").
   166  
   167  parse_backend_providers
   168  
   169  create_loopbacks
   170  
   171  if ! AIS_BACKEND_PROVIDERS=${AIS_BACKEND_PROVIDERS}  make --no-print-directory -C ${AISTORE_PATH} node; then
   172    exit_error "failed to compile 'aisnode' binary"
   173  fi
   174  
   175  # Not really used for local testing but to keep aisnode_config.sh quiet
   176  GRAPHITE_PORT=2003
   177  GRAPHITE_SERVER="127.0.0.1"
   178  
   179  #
   180  # generate conf file(s) based on the settings/selections above
   181  #
   182  if [ "${!#}" != "--dont-generate-configs" ]; then
   183    for (( c=START; c<=END; c++ )); do
   184      AIS_CONF_DIR="$HOME/.ais$NEXT_TIER$c"
   185      INSTANCE=$c
   186      mkdir -p "$AIS_CONF_DIR"
   187      AIS_CONF_FILE="$AIS_CONF_DIR/ais.json"
   188      AIS_LOCAL_CONF_FILE="$AIS_CONF_DIR/ais_local.json"
   189      AIS_LOG_DIR="$LOG_ROOT/$c/log"
   190      source "${AISTORE_PATH}/deploy/dev/local/aisnode_config.sh"
   191  
   192      ((PORT++))
   193      ((PORT_INTRA_CONTROL++))
   194      ((PORT_INTRA_DATA++))
   195    done
   196  fi
   197  
   198  # run all daemons
   199  CMD="${GOPATH}/bin/aisnode"
   200  listening_on="Proxies are listening on ports: "
   201  if [ $PROXY_CNT -eq 1 ]; then
   202    listening_on="Proxy is listening on port: "
   203  fi
   204  loopback=""
   205  if [[ "$TEST_LOOPBACK_COUNT" != "0" ]] ; then
   206    loopback="-loopback"
   207  fi
   208  for (( c=START; c<=END; c++ )); do
   209    AIS_CONF_DIR="$HOME/.ais${NEXT_TIER}$c"
   210    AIS_CONF_FILE="$AIS_CONF_DIR/ais.json"
   211    AIS_LOCAL_CONF_FILE="$AIS_CONF_DIR/ais_local.json"
   212  
   213    PROXY_PARAM="${AIS_NODE_FLAGS} -config=${AIS_CONF_FILE} -local_config=${AIS_LOCAL_CONF_FILE} -role=proxy -ntargets=${TARGET_CNT} ${RUN_ARGS}"
   214    TARGET_PARAM="${AIS_NODE_FLAGS} -config=${AIS_CONF_FILE} -local_config=${AIS_LOCAL_CONF_FILE} -role=target ${RUN_ARGS} $loopback"
   215  
   216    pub_port=$(grep "\"port\":" ${AIS_LOCAL_CONF_FILE} | awk '{ print $2 }')
   217    pub_port=${pub_port:1:$((${#pub_port} - 3))}
   218    if [[ $c -eq 0 && $PROXY_CNT -gt 0 ]]; then
   219      run_cmd "${CMD} ${PROXY_PARAM}"
   220      listening_on+=${pub_port}
   221  
   222      # Wait for the proxy to start up
   223      sleep 2
   224    elif [[ $c -lt ${PROXY_CNT} ]]; then
   225      run_cmd "${CMD} ${PROXY_PARAM}"
   226      listening_on+=", ${pub_port}"
   227    else
   228      run_cmd "${CMD} ${TARGET_PARAM}"
   229    fi
   230  done
   231  
   232  if [[ $AIS_AUTH_ENABLED == "true" ]]; then
   233  	exit_error "env var 'AIS_AUTH_ENABLED' is deprecated (use 'AIS_AUTHN_ENABLED')"
   234  	exit 1
   235  fi
   236  if [[ $AIS_AUTHN_ENABLED == "true" ]]; then
   237    # conf file for authn
   238    AIS_AUTHN_CONF_DIR="${APP_CONF_DIR}/authn"
   239    mkdir -p "$AIS_AUTHN_CONF_DIR"
   240    AIS_AUTHN_LOG_DIR="$LOG_ROOT/authn/log"
   241    source "${AISTORE_PATH}/deploy/dev/local/authn_config.sh"
   242  
   243    if ! make --no-print-directory -C ${AISTORE_PATH} authn; then
   244      exit_error "failed to compile 'authn' binary"
   245    fi
   246    run_cmd "${GOPATH}/bin/authn -config=${AIS_AUTHN_CONF_DIR}"
   247  fi
   248  
   249  if [[ $MODE == "debug" ]]; then
   250     sleep 1.5
   251  else
   252     sleep 0.1
   253  fi
   254  
   255  if command -v pgrep &> /dev/null; then
   256     run_count=$(pgrep -a aisnode | grep -c "${NEXT_TIER}")
   257     if [[ "${run_count}" -eq $((TARGET_CNT + PROXY_CNT)) ]]; then
   258        echo "${listening_on}"
   259        if [[ -z $DEPLOY_AS_NEXT_TIER ]]; then
   260           echo "Primary endpoint: ${AIS_PRIMARY_URL}"
   261        fi
   262     fi
   263  else
   264     echo "Warning: pgrep not found"
   265     echo "${listening_on}"
   266  fi