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

     1  #!/bin/bash
     2  
     3  ############################################
     4  #
     5  # Usage: kill.sh [--force|-f]
     6  #
     7  ############################################
     8  
     9  wait_for() {
    10    i=0
    11    for pid in $(pgrep "$1" | tr '\n' ' '); do
    12      while kill -0 "${pid}" 2>/dev/null; do
    13        sleep 0.1
    14        i=$((i + 1))
    15        if [[ $i -ge 70 ]]; then # timeout 7s
    16           break 2
    17        fi
    18      done
    19    done
    20    for pid in $(pgrep "$1" | tr '\n' ' '); do
    21      kill -9 "${pid}" 2>/dev/null
    22    done
    23  }
    24  
    25  
    26  signal=SIGINT
    27  
    28  while (( "$#" )); do
    29    case "$1" in
    30      --force|-f) signal=SIGKILL; shift;;
    31      *) echo "fatal: unknown argument '$1'"; exit 1;;
    32    esac
    33  done
    34  
    35  pkill "-${signal}" aisnode
    36  wait_for aisnode
    37  
    38  pkill "-${signal}" authn
    39  wait_for authn