...

Text file src/github.com/emissary-ingress/emissary/v3/python/entrypoint.sh

Documentation: github.com/emissary-ingress/emissary/v3/python

     1#!/bin/bash
     2
     3# Copyright 2018 Datawire. All rights reserved.
     4#
     5# Licensed under the Apache License, Version 2.0 (the "License");
     6# you may not use this file except in compliance with the License.
     7# You may obtain a copy of the License at
     8#
     9#     http://www.apache.org/licenses/LICENSE-2.0
    10#
    11# Unless required by applicable law or agreed to in writing, software
    12# distributed under the License is distributed on an "AS IS" BASIS,
    13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14# See the License for the specific language governing permissions and
    15# limitations under the License
    16
    17# THE DEFAULT BOOT SEQUENCE IS NOW entrypoint.go. HOWEVER, we'll stick
    18# with entrypoint.sh when the --dev-magic parameter is present. This
    19# is currently used only for test_scout.py.  This is a BRUTAL HACK.
    20
    21if [ "$1" != "--dev-magic" ]; then
    22  exec busyambassador entrypoint "$@"   # See comment above.
    23fi
    24
    25DEVMAGIC=yes
    26
    27# If we are here, define AMBASSADOR_FAST_RECONFIGURE, to make
    28# _absolutely certain_ that diagd's localhost checks are in sync with
    29# what's actually running...
    30export AMBASSADOR_FAST_RECONFIGURE=false
    31
    32ENTRYPOINT_DEBUG=
    33
    34log () {
    35    local now
    36
    37    now=$(date +"%Y-%m-%d %H:%M:%S")
    38    echo "${now} AMBASSADOR INFO ${@}" >&2
    39}
    40
    41debug () {
    42    local now
    43
    44    if [ -n "$ENTRYPOINT_DEBUG" ]; then
    45        now=$(date +"%Y-%m-%d %H:%M:%S")
    46        echo "${now} AMBASSADOR DEBUG ${@}" >&2
    47    fi
    48}
    49
    50wait_for_url () {
    51    local name url tries_left delay status
    52
    53    name="$1"
    54    url="$2"
    55
    56    tries_left=10
    57    delay=1
    58
    59    while (( tries_left > 0 )); do
    60        debug "pinging $name ($tries_left)..."
    61
    62        status=$(curl -s -o /dev/null -w "%{http_code}" $url)
    63
    64        if [ "$status" = "200" ]; then
    65            break
    66        fi
    67
    68        tries_left=$(( tries_left - 1 ))
    69        sleep $delay
    70        delay=$(( delay * 2 ))
    71        if (( delay > 10 )); then delay=5; fi
    72    done
    73
    74    if (( tries_left <= 0 )); then
    75        log "giving up on $name and hoping for the best..."
    76    else
    77        log "$name running"
    78    fi
    79}
    80
    81################################################################################
    82# CONFIG PARSING                                                               #
    83################################################################################
    84
    85ambassador_root="/ambassador"
    86
    87export LC_ALL=C.UTF-8
    88export LANG=C.UTF-8
    89
    90# If we have an AGENT_SERVICE, but no AMBASSADOR_ID, force AMBASSADOR_ID
    91# from the AGENT_SERVICE.
    92
    93if [ -z "$AMBASSADOR_ID" -a -n "$AGENT_SERVICE" ]; then
    94    export AMBASSADOR_ID="intercept-${AGENT_SERVICE}"
    95    log "Intercept: set AMBASSADOR_ID to $AMBASSADOR_ID"
    96fi
    97
    98export AMBASSADOR_NAMESPACE="${AMBASSADOR_NAMESPACE:-default}"
    99export AMBASSADOR_CONFIG_BASE_DIR="${AMBASSADOR_CONFIG_BASE_DIR:-$ambassador_root}"
   100export ENVOY_DIR="${AMBASSADOR_CONFIG_BASE_DIR}/envoy"
   101export ENVOY_BOOTSTRAP_FILE="${AMBASSADOR_CONFIG_BASE_DIR}/bootstrap-ads.json"
   102export ENVOY_BASE_ID="${AMBASSADOR_ENVOY_BASE_ID:-0}"
   103
   104export APPDIR="${APPDIR:-$ambassador_root}"
   105
   106# If we don't set PYTHON_EGG_CACHE explicitly, /.cache is set by
   107# default, which fails when running as a non-privileged user
   108export PYTHON_EGG_CACHE="${PYTHON_EGG_CACHE:-$AMBASSADOR_CONFIG_BASE_DIR}/.cache"
   109export PYTHONUNBUFFERED=true
   110
   111log "running with dev magic"
   112diagd --dev-magic

View as plain text