github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/build/ndm-daemonset/entrypoint.sh (about)

     1  #!/bin/bash
     2  # Copyright 2018-2020 The OpenEBS Authors. All rights reserved.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  export GOTRACEBACK=crash
    17  
    18  # openebs base directory inside the container
    19  OPENEBS_BASE_DIR="/var/openebs"
    20  # ndm base directory inside the container. It will be the ndm
    21  # directory inside openebs base directory
    22  NDM_BASE_DIR="${OPENEBS_BASE_DIR}/ndm"
    23  
    24  # set ulimit to 0, if the core dump is not enabled
    25  if [ -z "$ENABLE_COREDUMP" ]; then
    26    ulimit -c 0
    27  else
    28    # making sure mountpath inside the container is available
    29    if ! [ -d "${NDM_BASE_DIR}" ]; then
    30      echo "OpenEBS/NDM Base directory not found"
    31      exit 1
    32    fi
    33    # set ulimit to unlimited and create a core directory for creating coredump
    34    echo "[entrypoint.sh] enabling core dump."
    35    ulimit -c unlimited
    36    echo "[entrypoint.sh] creating ${NDM_BASE_DIR}/core if not exists."
    37    mkdir -p "${NDM_BASE_DIR}/core"
    38    echo "[entrypoint.sh] changing directory to ${NDM_BASE_DIR}/core"
    39    cd "${NDM_BASE_DIR}/core" || exit
    40  fi
    41  
    42  echo "[entrypoint.sh] launching ndm process."
    43  /usr/sbin/ndm start "$@" &
    44  
    45  #sigterm caught SIGTERM signal and forward it to child process
    46  _sigterm() {
    47    echo "[entrypoint.sh] caught SIGTERM signal forwarding to pid [$child]."
    48    kill -TERM "$child" 2> /dev/null
    49    waitForChildProcessToFinish
    50  }
    51  
    52  #sigint caught SIGINT signal and forward it to child process
    53  _sigint() {
    54    echo "[entrypoint.sh] caught SIGINT signal forwarding to pid [$child]."
    55    kill -INT "$child" 2> /dev/null
    56    waitForChildProcessToFinish
    57  }
    58  
    59  #waitForChildProcessToFinish waits for child process to finish
    60  waitForChildProcessToFinish(){
    61      while ps -p "$child" > /dev/null; do sleep 1; done;
    62  }
    63  
    64  trap _sigint INT
    65  trap _sigterm SIGTERM
    66  
    67  child=$!
    68  wait $child