From 6313d457b5c6877750037ca078ea30bc151cdcf7 Mon Sep 17 00:00:00 2001 From: Schneider Roland Date: Sun, 1 Jun 2025 14:10:12 +0200 Subject: [PATCH] env infra: improve restart script --- environments/infra/Jenkinsfile | 2 ++ environments/infra/restart.sh | 32 ++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/environments/infra/Jenkinsfile b/environments/infra/Jenkinsfile index 41d5741..64a40b4 100644 --- a/environments/infra/Jenkinsfile +++ b/environments/infra/Jenkinsfile @@ -6,6 +6,8 @@ pipeline { stage('Restart') { steps { sshPublisher(publishers: [sshPublisherDesc(configName: 'infra.1', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: ''' + logger -t jenkins-ssh-publisher "Restarting infra environment" + pwd cd /home/rschneider/infra/ git pull cd environments/infra diff --git a/environments/infra/restart.sh b/environments/infra/restart.sh index 0a9d347..f6f104c 100644 --- a/environments/infra/restart.sh +++ b/environments/infra/restart.sh @@ -1,20 +1,24 @@ #!/usr/bin/env bash -PROJECT_ROOT=$(readlink -f "$(dirname "$(realpath "$0")")/../..") -echo "Project root directory: $PROJECT_ROOT" +log() { + echo "$1" + logger -t infra-update "$1" +} +PROJECT_ROOT=$(readlink -f "$(dirname "$(realpath "$0")")/../..") +log "Project root directory: $PROJECT_ROOT" # Restart all projects except 'traefik' and 'jenkins' -for dir in $(find "$PROJECT_ROOT" -type d -path "*/docker-compose/*" -mindepth 3 -maxdepth 3 -not -path "*/docker-compose/*/*" | grep -v "/traefik/docker-compose/traefik" | grep -v "/jenkins/docker-compose/jenkins"); do - echo "Processing directory: $dir" - cd "$dir" || { echo "Failed to enter directory: $dir"; continue; } +for dir in $(find "$PROJECT_ROOT" -mindepth 3 -maxdepth 3 -not -path "*/docker-compose/*/*" -type d -path "*/docker-compose/*" | grep -v "/traefik/docker-compose/traefik" | grep -v "/jenkins/docker-compose/jenkins"); do + log "Processing directory: $dir" + cd "$dir" || { log "Failed to enter directory: $dir"; continue; } # Execute docker compose commands if [ -f "docker-compose.yml" ] || [ -f "docker-compose.yaml" ]; then - echo "Running docker compose down && docker compose up -d in $dir" - # docker compose down && docker compose up -d + log "Running docker compose down && docker compose up -d in $dir" + docker compose down && docker compose up -d else - echo "No docker-compose file found in $dir, skipping..." + log "No docker-compose file found in $dir, skipping..." fi # Return to the project root @@ -22,16 +26,16 @@ for dir in $(find "$PROJECT_ROOT" -type d -path "*/docker-compose/*" -mindepth 3 done # Restart 'traefik' project last -TRAEFIK_DIR=$(find "$PROJECT_ROOT" -type d -path "*/traefik/docker-compose/traefik" -mindepth 3 -maxdepth 3 -not -path "*/docker-compose/*/*") +TRAEFIK_DIR=$(find "$PROJECT_ROOT" -mindepth 3 -maxdepth 3 -not -path "*/docker-compose/*/*" -type d -path "*/traefik/docker-compose/traefik") if [ -n "$TRAEFIK_DIR" ]; then - echo "Processing traefik directory: $TRAEFIK_DIR" - cd "$TRAEFIK_DIR" || { echo "Failed to enter traefik directory: $TRAEFIK_DIR"; exit 1; } + log "Processing traefik directory: $TRAEFIK_DIR" + cd "$TRAEFIK_DIR" || { log "Failed to enter traefik directory: $TRAEFIK_DIR"; exit 1; } # Execute docker compose commands if [ -f "docker-compose.yml" ] || [ -f "docker-compose.yaml" ]; then - echo "Running docker compose down && docker compose up -d in $TRAEFIK_DIR" - # docker compose down && docker compose up -d + log "Running docker compose down && docker compose up -d in $TRAEFIK_DIR" + docker compose down && docker compose up -d else - echo "No docker-compose file found in $TRAEFIK_DIR, skipping..." + log "No docker-compose file found in $TRAEFIK_DIR, skipping..." fi fi