# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. # Common variables and functions that may be useful for scripts IN THIS # DIRECTORY. Should be sourced as follows: # # source "${0%/*}/common.sh" # # WARNING: Some system variables, like the Config Server's, are also hardcoded # in the Docker image startup scripts. declare -r SCRIPT_NAME="${0##*/}" declare -r SCRIPT_DIR="${0%/*}" # TODO: Find a better name. Consider having separate images for config-server # and node-admin. declare -r DOCKER_IMAGE="vespa-local:latest" declare -r APPLICATION_STORAGE_ROOT="/home/docker/container-storage" declare -r ROOT_DIR_SHARED_WITH_HOST=shared # The 172.18.0.0/16 network is in IPDB. declare -r NETWORK_PREFIX=172.18 declare -r NETWORK_PREFIX_BITLENGTH=16 # Hostnames, IP addresses, names, etc of the infrastructure containers. declare -r HOST_BRIDGE_INTERFACE=vespa declare -r HOST_BRIDGE_IP="$NETWORK_PREFIX.0.1" declare -r HOST_BRIDGE_NETWORK="$NETWORK_PREFIX.0.0/$NETWORK_PREFIX_BITLENGTH" declare -r NODE_ADMIN_CONTAINER_NAME=node-admin declare -r CONFIG_SERVER_CONTAINER_NAME=config-server declare -r CONFIG_SERVER_HOSTNAME="$CONFIG_SERVER_CONTAINER_NAME" declare -r CONFIG_SERVER_IP="$NETWORK_PREFIX.1.1" declare -r CONFIG_SERVER_PORT=19071 declare -r DEFAULT_HOSTED_VESPA_REGION=local-region declare -r DEFAULT_HOSTED_VESPA_ENVIRONMENT=prod # Hostnames, IP addresses, names, etc of the application containers. Hostname # and container names are of the form $PREFIX$N, where N is a number between 1 # and $NUM_APP_CONTAINERS. The IP is $APP_NETWORK_PREFIX.$N. declare -r APP_NETWORK_PREFIX="$NETWORK_PREFIX.2" declare -r APP_CONTAINER_NAME_PREFIX=cnode- declare -r APP_HOSTNAME_PREFIX="$APP_CONTAINER_NAME_PREFIX" declare -r DEFAULT_NUM_APP_CONTAINERS=20 # Statically allocated number of nodes. declare -r TENANT_NAME=localtenant # May be 'vm' if docker hosts runs within a VM (osx). Default is native/Fedora. declare -r NETWORK_TYPE="${NETWORK_TYPE:-local}" # Allowed program opions declare OPTION_NUM_NODES # Set from --num-nodes or DEFAULT_NUM_APP_CONTAINERS, see Main. declare OPTION_WAIT # Set from --wait or true, see Main. declare OPTION_HV_REGION # Set from --hv-region or DEFAULT_HOSTED_VESPA_REGION, see Main. declare OPTION_HV_ENV # Set from --hv-env or DEFAULT_HOSTED_VESPA_ENVIRONMENT, see Main. declare NUM_APP_CONTAINERS # Set from OPTION_NUM_NODES or DEFAULT_NUM_APP_CONTAINERS, see Main. function Fail { printf "%s\n" "$@" >&2 exit 1 } # Used to help scripts with implementing the Usage function. The intended usage # is: # # function Usage { # UsageHelper "$@" <&2 if (($# > 0)) then printf "%s\n\n" "$*" fi # Print to stdout (which has been redirected to stderr) what's on # stdin. This will print the usage-string. cat exit 1 } # See Main function Restart { Stop Start "$@" } # Use Main as follows: # # Pass all script arguments to Main: # # Main "$@" # # Main will parse the arguments as follows. It assumes the arguments have # the following form: # # script.sh [ |