env infra: improve restart script

This commit is contained in:
Schneider Roland 2025-06-01 14:10:12 +02:00
parent 62eb507a5e
commit 6313d457b5
2 changed files with 20 additions and 14 deletions

View File

@ -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

View File

@ -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