openvidu/openvidu-server/deployments/enterprise-ha/docker-compose/node/openvidu

338 lines
11 KiB
Bash
Executable File

#!/bin/bash
# Support docker compose v1 and v2
shopt -s expand_aliases
alias docker-compose='docker compose'
if ! docker compose version &> /dev/null; then
unalias docker-compose
fi
# Change default http timeout for slow networks
export COMPOSE_HTTP_TIMEOUT=500
export DOCKER_CLIENT_TIMEOUT=500
# Deployed images by media-node-controller
IMAGES=(
"kurento-media-server"
"docker.elastic.co/beats/filebeat"
"docker.elastic.co/beats/metricbeat"
"openvidu/media-node-controller"
"openvidu/speech-to-text-service"
"openvidu/mediasoup-controller"
"openvidu/openvidu-coturn"
)
docker_command_by_container_image() {
IMAGE_NAME=$1
COMMAND=$2
if [[ -n "${IMAGE_NAME}" ]]; then
CONTAINERS="$(docker ps -a | grep "${IMAGE_NAME}" | awk '{print $1}')"
for CONTAINER_ID in $CONTAINERS; do
if [[ -n "${CONTAINER_ID}" ]] && [[ -n "${COMMAND}" ]]; then
bash -c "docker ${COMMAND} ${CONTAINER_ID}"
fi
done
fi
}
collect_basic_information() {
LINUX_VERSION=$(lsb_release -d)
DOCKER_PS=$(docker ps)
DOCKER_VERSION=$(docker version --format '{{.Server.Version}}')
DOCKER_COMPOSE_VERSION=$(docker-compose version --short)
OV_FOLDER="${PWD}"
OV_VERSION=$(grep 'Openvidu Version:' "${OV_FOLDER}/docker-compose.yml" | awk '{ print $4 }')
CONTAINERS=$(docker ps | awk '{if(NR>1) print $NF}')
OV_TYPE_INSTALLATION=$(grep 'Installation Mode:' "${OV_FOLDER}/docker-compose.yml" | awk '{ print $4,$5 }')
TREE_OV_DIRECTORY=$(find "." ! -path '*/0/*' | sed -e "s/[^-][^\/]*\// |/g" -e "s/|\([^ ]\)/|-\1/")
}
version_ov() {
collect_basic_information
printf '\nOpenvidu Information:'
printf '\n'
printf '\n OpenVidu Edition: Enterprise HA'
printf '\n Installation Type: %s' "${OV_TYPE_INSTALLATION}"
printf '\n Openvidu Version: %s' "${OV_VERSION}"
printf '\n'
printf '\nSystem Information:'
printf '\n'
printf '\n Linux Version:'
printf '\n - %s' "${LINUX_VERSION}"
printf '\n Docker Version: %s' "${DOCKER_VERSION}"
printf '\n Docker Compose Version: %s' "${DOCKER_COMPOSE_VERSION}"
printf '\n'
printf '\nInstallation Information:'
printf '\n'
printf '\n Installation Folder: %s' "${OV_FOLDER}"
printf '\n Installation Folder Tree:'
printf '\n%s' "$(echo "${TREE_OV_DIRECTORY}" | sed -e 's/.//' -e ':a' -e 'N;$!ba' -e 's/\n/\n\t/g')"
printf '\n'
printf '\nDocker Running Services:'
printf '\n'
printf '\n %s' "$(echo "${DOCKER_PS}" | sed -e ':a' -e 'N;$!ba' -e 's/\n/\n\t/g')"
printf '\n'
}
generate_report() {
collect_basic_information
REPORT_CREATION_DATE=$(date +"%d-%m-%Y")
REPORT_CREATION_TIME=$(date +"%H:%M:%S")
REPORT_NAME="openvidu-report-${REPORT_CREATION_DATE}-$(date +"%H-%M").txt"
REPORT_OUTPUT="${OV_FOLDER}/${REPORT_NAME}"
{
printf "\n ======================================="
printf "\n = REPORT INFORMATION ="
printf "\n ======================================="
printf '\n'
printf '\n Creation Date: %s' "${REPORT_CREATION_DATE}"
printf '\n Creation Time: %s' "${REPORT_CREATION_TIME}"
printf '\n'
printf "\n ======================================="
printf "\n = OPENVIDU INFORMATION ="
printf "\n ======================================="
printf '\n'
printf '\n OpenVidu Edition: Enterprise HA'
printf '\n Installation Type: %s' "${OV_TYPE_INSTALLATION}"
printf '\n Openvidu Version: %s' "${OV_VERSION}"
# printf '\n Openvidu Call Version: %s' "${OV_CALL_VERSION}"
printf '\n'
printf "\n ======================================="
printf "\n = SYSTEM INFORMATION ="
printf "\n ======================================="
printf '\n'
printf '\n Linux Version:'
printf '\n - %s' "${LINUX_VERSION}"
printf '\n Docker Version: %s' "${DOCKER_VERSION}"
printf '\n Docker Compose Version: %s' "${DOCKER_COMPOSE_VERSION}"
printf '\n'
printf "\n ======================================="
printf "\n = INSTALLATION INFORMATION ="
printf "\n ======================================="
printf '\n'
printf '\n Installation Folder: %s' "${OV_FOLDER}"
printf '\n Installation Folder Tree:'
printf '\n%s' "$(echo "${TREE_OV_DIRECTORY}" | sed -e 's/.//' -e ':a' -e 'N;$!ba' -e 's/\n/\n\t/g')"
printf '\n'
printf "\n ======================================="
printf "\n = DOCKER RUNNING SERVICES ="
printf "\n ======================================="
printf '\n'
printf '\n %s' "$(echo "${DOCKER_PS}" | sed -e ':a' -e 'N;$!ba' -e 's/\n/\n\t/g')"
printf '\n'
printf "\n ======================================="
printf "\n = CONFIGURATION FILES ="
printf "\n ======================================="
printf '\n'
printf '\n ================ .env ================='
printf '\n'
printf '\n'
cat < "${OV_FOLDER}/.env" | sed -r -e "s/OPENVIDU_SECRET=.+/OPENVIDU_SECRET=****/" -e "s/OPENVIDU_PRO_LICENSE=.+/OPENVIDU_PRO_LICENSE=****/" -e "s/ELASTICSEARCH_PASSWORD=.+/ELASTICSEARCH_PASSWORD=****/"
printf '\n'
printf '\n ========= docker-compose.yml =========='
printf '\n'
printf '\n'
cat "${OV_FOLDER}/docker-compose.yml"
printf '\n'
printf '\n ==== docker-compose.override.yml ===='
printf '\n'
printf '\n'
if [ -f "${OV_FOLDER}/docker-compose.override.yml" ]; then
cat < "${OV_FOLDER}/docker-compose.override.yml"
else
printf '\n The docker-compose.override.yml file is not present'
fi
printf '\n'
printf '\n'
printf "\n ======================================="
printf "\n = LOGS ="
printf "\n ======================================="
for CONTAINER in $CONTAINERS
do
printf '\n'
printf "\n ---------------------------------------"
printf "\n %s" "$CONTAINER"
printf "\n ---------------------------------------"
printf '\n'
docker logs "$CONTAINER"
printf "\n ---------------------------------------"
printf '\n'
printf '\n'
done
printf "\n ======================================="
printf "\n = CONTAINER ENVS VARIABLES ="
printf "\n ======================================="
for CONTAINER in $CONTAINERS
do
printf '\n'
printf "\n ======================================="
printf "\n %s" "$CONTAINER"
printf "\n ---------------------------------------"
printf '\n'
docker exec "$CONTAINER" env
printf "\n ---------------------------------------"
printf '\n'
printf '\n'
done
} >> "${REPORT_OUTPUT}" 2>&1
printf "\n Generation of the report completed with success"
printf "\n You can get your report at path '%s'" "${REPORT_OUTPUT}"
printf "\n"
}
is_external_url() {
local URL=$1
if [[ -z "$URL" ]]; then
return 1
fi
if [[ "${URL}" == *"localhost"* ]] || [[ "${URL}" == *"127.0.0.1"* ]] || [[ "${URL}" == *"::1"* ]]; then
return 1
else
return 0
fi
}
print_env_error() {
printf "\n ERROR: You must set the '%s' variable in the .env file" "${1}"
printf "\n"
}
check_non_empty_parameters() {
local NON_EMPTY_ENV_VARS=("$@")
for ENV_VAR_NAME in "${NON_EMPTY_ENV_VARS[@]}" ; do
ENV_VAR_VALUE=$(grep -v '^#' .env | grep "${ENV_VAR_NAME}" | cut -d '=' -f2)
if [[ -z "${ENV_VAR_VALUE}" ]]; then
print_env_error "${ENV_VAR_NAME}"
exit 1
fi
done
}
get_env_var_value() {
local ENV_VAR_NAME=$1
local ENV_VAR_VALUE
ENV_VAR_VALUE=$(grep -v '^#' .env | grep "${ENV_VAR_NAME}" | cut -d '=' -f2)
echo "${ENV_VAR_VALUE}"
}
check_env_var_is_value() {
local ENV_VAR_NAME=$1
local ENV_VAR_VALUE=$2
local ENV_VAR_VALUE_TO_CHECK
ENV_VAR_VALUE_TO_CHECK=$(get_env_var_value "${ENV_VAR_NAME}")
if [[ "${ENV_VAR_VALUE_TO_CHECK}" != "${ENV_VAR_VALUE}" ]]; then
print_env_error "${ENV_VAR_NAME}"
exit 1
fi
}
start_openvidu() {
export INITIAL_CONFIG_SYNC=true
if ! docker-compose up --exit-code-from replication-manager replication-manager; then
printf "\n ERROR: Openvidu Node failed to start"
printf "\n"
unset INITIAL_CONFIG_SYNC
docker-compose down
exit 1
fi
docker-compose down
unset INITIAL_CONFIG_SYNC
docker-compose up -d
}
stop_containers() {
printf "Stopping containers..."
for IMAGE in "${IMAGES[@]}"; do
docker_command_by_container_image "${IMAGE}" "rm -f"
done
}
usage() {
printf "Usage: \n\t openvidu [command]"
printf "\n\nAvailable Commands:"
printf "\n\tstart\t\t\tStart all services"
printf "\n\tstop\t\t\tStop all services"
printf "\n\trestart\t\t\tRestart all stopped and running services"
printf "\n\tlogs\t\t\tShow openvidu-server logs"
printf "\n\tupgrade\t\t\tUpgrade to the latest Openvidu version"
printf "\n\tupgrade [version]\tUpgrade to the specific Openvidu version"
printf "\n\tversion\t\t\tShow version of Openvidu Server"
printf "\n\treport\t\t\tGenerate a report with the current status of Openvidu"
printf "\n\thelp\t\t\tShow help for openvidu command"
printf "\n"
}
[[ -z "${FOLLOW_OPENVIDU_LOGS}" ]] && FOLLOW_OPENVIDU_LOGS=true
case $1 in
start)
start_openvidu
if [[ "${FOLLOW_OPENVIDU_LOGS}" == "true" ]]; then
# Docker compose logs of openvidu-server and repliation-manager containers
docker-compose logs -f --tail 10 openvidu-server replication-manager
fi
;;
stop)
docker-compose down
stop_containers
;;
restart)
docker-compose down
stop_containers
start_openvidu
if [[ "${FOLLOW_OPENVIDU_LOGS}" == "true" ]]; then
docker-compose logs -f --tail 10 openvidu-server replication-manager
fi
;;
logs)
case "${2-}" in
--follow|-f)
docker-compose logs -f --tail 10 openvidu-server replication-manager
;;
*)
docker-compose logs openvidu-server replication-manager
;;
esac
;;
version)
version_ov
;;
report)
read -r -p " You are about to generate a report on the current status of Openvidu, this may take some time. Do you want to continue? [y/N]: " response
case "$response" in
[yY][eE][sS]|[yY])
generate_report
;;
*)
exit 0
;;
esac
;;
*)
usage
;;
esac