diff --git a/scripts/destroy-demo.sh b/scripts/destroy-demo.sh index ebd0615..7675796 100755 --- a/scripts/destroy-demo.sh +++ b/scripts/destroy-demo.sh @@ -11,15 +11,20 @@ setupDirs # Export more environment variables exportPaths +# Read PROJECT_NAME from the temporary file +PROJECT_NAME=$(cat /tmp/project_name.txt) + +echo "$INFO Destroying $PROJECT_NAME project..." + INSTALLED_DOCKER_VERSION=$(docker version -f "{{.Server.Version}}") MINIMUM_REQUIRED_DOCKER_VERSION_REGEX="^((([2-9][1-9]|[3-9][0]|[0-9]{3,}).*)|(20\.([0-9]{3,}|[1-9][1-9]|[2-9][0]).*)|(20\.10\.([0-9]{3,}|[2-9][0-9]|[1][3-9])))" if [[ $INSTALLED_DOCKER_VERSION =~ $MINIMUM_REQUIRED_DOCKER_VERSION_REGEX ]]; then echo "$INFO Destroying demo service..." - docker compose -p ozone $dockerComposeDemoCLIOptions down -v + docker compose -p $PROJECT_NAME $dockerComposeDemoCLIOptions down -v echo "$INFO Destroying proxy service..." - docker compose -p ozone $dockerComposeProxyCLIOptions down -v + docker compose -p $PROJECT_NAME $dockerComposeProxyCLIOptions down -v echo "$INFO Destroying Ozone services..." - docker compose -p ozone $dockerComposeOzoneCLIOptions down -v --remove-orphans + docker compose -p $PROJECT_NAME $dockerComposeOzoneCLIOptions down -v --remove-orphans else echo "$ERROR Docker versions < 20.10.13 are not supported" fi diff --git a/scripts/start.sh b/scripts/start.sh index 84609f2..6e15743 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -29,6 +29,29 @@ if [ "$DEMO" == "true" ]; then echo "→ NUMBER_OF_DEMO_PATIENTS=$NUMBER_OF_DEMO_PATIENTS" fi +# Check if ozone-info.json exists and read project name from it +ozoneInfo="../$DISTRO_PATH/ozone-info.json" +if [ -f "$ozoneInfo" ]; then + export PROJECT_NAME=$(grep -o '"name":\s*"[^\"]*"' "$ozoneInfo" | cut -d'"' -f4) +else + export PROJECT_NAME="ozone" +fi +echo "$PROJECT_NAME" > /tmp/project_name.txt + +if ! isOzoneRunning "$PROJECT_NAME"; then + echo "$INFO Starting Ozone project with name: $PROJECT_NAME" +fi + +# Check if an instance of Ozone is already running +suffix=0 +while isOzoneRunning "$PROJECT_NAME"; do + echo "$WARN An instance of Ozone is already running with the name: $PROJECT_NAME" + suffix=$((suffix + 1)) + export PROJECT_NAME="$PROJECT_NAME-$suffix" + echo "$INFO Starting a new instance of Ozone with name: $PROJECT_NAME" + echo "$PROJECT_NAME" > /tmp/project_name.txt +done + INSTALLED_DOCKER_VERSION=$(docker version -f "{{.Server.Version}}") MINIMUM_REQUIRED_DOCKER_VERSION_REGEX="^((([2-9][1-9]|[3-9][0]|[0-9]{3,}).*)|(20\.([0-9]{3,}|[1-9][1-9]|[2-9][0]).*)|(20\.10\.([0-9]{3,}|[2-9][0-9]|[1][3-9])))" if [[ $INSTALLED_DOCKER_VERSION =~ $MINIMUM_REQUIRED_DOCKER_VERSION_REGEX ]]; then @@ -40,10 +63,10 @@ if [[ $INSTALLED_DOCKER_VERSION =~ $MINIMUM_REQUIRED_DOCKER_VERSION_REGEX ]]; th # Pull Ozone Docker images echo "$INFO Pulling ${OZONE_LABEL:-Ozone FOSS} images..." - docker compose -p ozone $dockerComposeOzoneCLIOptions pull + docker compose -p $PROJECT_NAME $dockerComposeOzoneCLIOptions pull # Set the Docker Compose command for Ozone - dockerComposeOzoneCommand="docker compose -p ozone $dockerComposeOzoneCLIOptions up -d --build" + dockerComposeOzoneCommand="docker compose -p $PROJECT_NAME $dockerComposeOzoneCLIOptions up -d --build" echo "$INFO Running ${OZONE_LABEL:-Ozone FOSS}..." echo "" echo "$dockerComposeOzoneCommand" @@ -57,7 +80,7 @@ if [[ $INSTALLED_DOCKER_VERSION =~ $MINIMUM_REQUIRED_DOCKER_VERSION_REGEX ]]; th # Run the Nginx Proxy service, if $TRAEFIK!=true if [ "$TRAEFIK" != "true" ]; then - dockerComposeProxyCommand="docker compose -p ozone $dockerComposeProxyCLIOptions up -d --build" + dockerComposeProxyCommand="docker compose -p $PROJECT_NAME $dockerComposeProxyCLIOptions up -d --build" echo "$INFO Running Nginx proxy service (\$TRAEFIK!=true)..." echo "" echo "$dockerComposeProxyCommand" @@ -69,7 +92,7 @@ if [[ $INSTALLED_DOCKER_VERSION =~ $MINIMUM_REQUIRED_DOCKER_VERSION_REGEX ]]; th # Run the Demo service if [ "$DEMO" == "true" ]; then - dockerComposeDemoCommand="docker compose -p ozone $dockerComposeDemoCLIOptions up -d" + dockerComposeDemoCommand="docker compose -p $PROJECT_NAME $dockerComposeDemoCLIOptions up -d" echo "$INFO Running demo service..." echo "" echo "$dockerComposeDemoCommand" diff --git a/scripts/utils.sh b/scripts/utils.sh index fd97c20..664435b 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -2,10 +2,12 @@ export TEXT_BLUE=`tput setaf 4` export TEXT_RED=`tput setaf 1` +export TEXT_YELLOW=`tput setaf 3` export BOLD=`tput bold` export RESET_FORMATTING=`tput sgr0` INFO="$TEXT_BLUE$BOLD[INFO]$RESET_FORMATTING" ERROR="$TEXT_RED$BOLD[ERROR]$RESET_FORMATTING" +WARN="$TEXT_YELLOW$BOLD[WARN]$RESET_FORMATTING" function setupDirs () { # Create the Ozone directory @@ -127,6 +129,16 @@ function setNginxHostnames { } +function isOzoneRunning { + local projectName=$1 + runningContainers=$(docker ps --filter "name=${projectName}" --format "{{.Names}}") + if [ -n "$runningContainers" ]; then + return 0 # true + else + return 1 # false + fi +} + function displayAccessURLsWithCredentials { services=() is_defined=()