github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/deploy/prod/k8s/aisnode_container/ais_docker_start.sh (about)

     1  #!/bin/bash
     2  
     3  echo "---------------------------------------------------"
     4  echo "aisnode $AIS_NODE_ROLE container startup at $(date)"
     5  echo "---------------------------------------------------"
     6  
     7  [[ -f /git-showbranch.out ]] && cat /git-showbranch.out
     8  
     9  cp -fv $AIS_CONF_FILE /etc/ais || exit 1
    10  cp -fv $AIS_LOCAL_CONF_FILE /etc/ais || exit 1
    11  cp -fv $STATSD_CONF_FILE /opt/statsd/statsd.conf || exit 1
    12  
    13  #
    14  # Somewhere to dump anything of interest that will be picked up but the
    15  # gather_log.sh script.
    16  #
    17  mkdir /var/log/aismisc
    18  
    19  #
    20  # Use environment variables from /var/ais_env/env file
    21  env_file=/var/ais_env/env
    22  if [[ -f  ${env_file} ]]; then
    23      source ${env_file}
    24  fi
    25  
    26  #
    27  # Informational
    28  #
    29  if [[ -f /etc/ais/.ais.smap ]]; then
    30      cat <<-EOM
    31       --- BEGIN cached .ais.smap ---
    32       $(usr/local/bin/xmeta -x -in=/etc/ais/.ais.smap)
    33       --- END cached .ais.smap ---
    34  EOM
    35  else
    36      echo "No cached .ais.smap"
    37  fi
    38  
    39  # token effort to allow StatsD to set up shop before ais tries to connect
    40  total_wait=0
    41  [[ $total_wait -le 2 ]] && sleep 2
    42  
    43  ARGS="-config=/etc/ais/$(basename -- $AIS_CONF_FILE) -local_config=/etc/ais/$(basename -- $AIS_LOCAL_CONF_FILE) -role=$AIS_NODE_ROLE"
    44  if [[ "$AIS_NODE_ROLE" = "proxy" ]]; then
    45      ARGS+=" -ntargets=$TARGETS"
    46  fi
    47  echo "aisnode args: $ARGS"
    48  
    49  while :
    50  do
    51      if [[ -e /usr/local/bin/aisnode ]]; then
    52          # the production Dockerfile places ais here
    53          /usr/local/bin/aisnode $ARGS
    54      elif [[ -e /go/bin/aisnode ]]; then
    55          # debug/source image with a built binary, use that
    56          /go/bin/aisnode $ARGS
    57      elif [[ -d /go/src/github.com/NVIDIA/aistore/ais ]]; then
    58          # if running from source tree then add flags to assist the debugger
    59          (cd /go/src/github.com/NVIDIA/aistore/ais && go run -gcflags="all=-N -l" setup/aisnode.go $ARGS)
    60      else
    61          echo "Cannot find an ais binary or source tree"
    62      exit 2
    63      fi
    64  
    65      rc=$?   # exit code from aisnode
    66  
    67      # logs will be present in `logsDir` directory of host
    68  
    69      # If the shutdown marker is present wait for the container to receive kill signal.
    70      # This is to ensure that the ais deamon scheduled to terminate isn't restarted by K8s.
    71      while [[ -f /var/ais_config/.ais.shutdown ]]; do
    72          echo "Waiting to receive kill signal"
    73          sleep 10
    74      done
    75  
    76      # Exit now if aisnode received SIGINT (see preStop lifecycle hook)
    77      [[ $rc -eq $((128 + 2)) ]] && exit 0
    78  
    79      # Ye olde debug hack - create this in the hostmount to cause us to
    80      # loop and restart on exit
    81      [[ -f "/etc/ais/debug_doloop" ]] || break
    82      echo "ais exited, restarting in loop per debug request in /etc/ais/debug_doloop"
    83      sleep 5 # slow any rapid-fail loops!
    84  
    85      # ... and use this to gate restart
    86      while [[ -f /etc/ais/debug_wait ]]; do
    87          echo "Waiting for /etc/ais/debug_wait to disappear"
    88          sleep 10
    89      done
    90  done