peacock-data-public-datasets-idc-mint / control_containers.sh
applied-ai-018's picture
Add files using upload-large-folder tool
45361be verified
#!/bin/bash
# Copyright (c) 2023 Habana Labs, Ltd. an Intel Company.Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SOURCE_DIR="$(cd "$(dirname "$0")" && pwd)"
source $SOURCE_DIR/config.properties
export PDSH_RCMD_TYPE=ssh
HOSTFILE="${HOSTFILE:-$SOURCE_DIR/hostfile}";
BASE_PDSH_CMD="pdsh -w ^$HOSTFILE \
export DOCKER_BUILDKIT=1; \
export $( cat $SOURCE_DIR/config.properties | grep -v "^#" | xargs ); "
DOCKER_COMPOSE_PATH="$DOCKER_DIR/docker-compose.yml"
BASE_DOCKER_CMD="$BASE_PDSH_CMD docker compose -f $DOCKER_COMPOSE_PATH"
show_help()
{
cat <<EOF
Usage: ./control_containers.sh [-b] [-u] [-d] [-r] [-h]
-b ...... Build image based on local Dockerfile
-u ...... Bring Containers Up
-d ...... Bring Containers Down
-r ...... Restart Containers
-h ...... Optional; show help
This script runs docker compose commands to handle mutli-node configurations.
Requirements:
- pdsh
- docker compose
- Dockerfile to build
EOF
}
build_image()
{
echo "Building Docker Images"
$BASE_DOCKER_CMD build
}
up_containers()
{
echo "Brining Docker Containers Up"
$BASE_DOCKER_CMD up -d
}
down_containers()
{
echo "Brining Docker Containers down"
$BASE_DOCKER_CMD down
}
restart_containers()
{
echo "Restarting Docker Containers"
$BASE_DOCKER_CMD restart
}
eval "$(ssh-agent -s)" > /dev/null
ssh-add "$SOURCE_DIR/ssh/mint_rsa" > /dev/null
while getopts budrh flag
do
case "${flag}" in
b) build_image ;;
u) up_containers ;;
d) down_containers ;;
r) restart_containers ;;
h) show_help >&2; exit 0 ;;
*) show_help >&2; exit 0 ;;
esac
done