diff --git a/roles/docker/tasks/main.yml b/roles/docker/tasks/main.yml index 36d0b112..52cf345c 100644 --- a/roles/docker/tasks/main.yml +++ b/roles/docker/tasks/main.yml @@ -1,4 +1,26 @@ --- +- name: Wait in a loop until the service update-docker.service is inactive + block: + - name: Check the status of update-docker.service + command: systemctl is-active update-docker.service + register: service_status + changed_when: false + failed_when: service_status.stdout == 'active' + + - name: Pause for 60 seconds if the service is still active + pause: + seconds: 60 + when: service_status.stdout == 'active' + become: true + until: service_status.stdout != 'active' + retries: 720 + delay: 10 + +- name: Abort if the service is still active after the maximum attempts + fail: + msg: "The update-docker.service is still active after the maximum number of attempts." + when: service_status.stdout == 'active' and service_status.attempts == 10 + - name: docker & docker compose install pacman: name: ['docker','docker-compose'] diff --git a/roles/system-update/meta/main.yml b/roles/system-update/meta/main.yml deleted file mode 100644 index 064fadd0..00000000 --- a/roles/system-update/meta/main.yml +++ /dev/null @@ -1,3 +0,0 @@ -dependencies: - - { role: system-pacman, when: ansible_distribution == 'Archlinux' } - - { role: system-apt-update, when: ansible_distribution == "Debian" } diff --git a/roles/system-apt-update/README.md b/roles/update-apt/README.md similarity index 85% rename from roles/system-apt-update/README.md rename to roles/update-apt/README.md index 0aa5d54c..a1fa0ebf 100644 --- a/roles/system-apt-update/README.md +++ b/roles/update-apt/README.md @@ -1,4 +1,4 @@ -# role system-apt-update +# role update-apt This role updates the packages # upgrade diff --git a/roles/system-apt-update/tasks/main.yml b/roles/update-apt/tasks/main.yml similarity index 100% rename from roles/system-apt-update/tasks/main.yml rename to roles/update-apt/tasks/main.yml diff --git a/roles/update-docker/README.md b/roles/update-docker/README.md new file mode 100644 index 00000000..50d43623 --- /dev/null +++ b/roles/update-docker/README.md @@ -0,0 +1,4 @@ +# update-docker +script to update docker-compose instances +## See +- [ChatGPT: Docker --force-recreate vs. --build](https://chat.openai.com/share/4cbf76a0-878b-4ce4-ba43-08a7b6dfcd0b) \ No newline at end of file diff --git a/roles/update-docker/files/update-docker-compose-instances.sh b/roles/update-docker/files/update-docker-compose-instances.sh new file mode 100644 index 00000000..88b28f86 --- /dev/null +++ b/roles/update-docker/files/update-docker-compose-instances.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# Check if a path argument was provided +if [ -z "$1" ]; then + echo "Please provide the path to the parent directory as a parameter." + exit 1 +fi + +# Iterate over all directories in the parent directory +for dir in "$1"/*; do + # Check if it is indeed a directory + if [ -d "$dir" ]; then + echo "Checking for updates in: $dir" + cd "$dir" + + # Check if directory is a Git repository + if [ -d ".git" ]; then + echo "Checking if the git repository is up to date." + git fetch + LOCAL=$(git rev-parse @) + REMOTE=$(git rev-parse @{u}) + + # If local commit differs from remote, pull the changes + if [ "$LOCAL" != "$REMOTE" ]; then + echo "Repository is not up to date. Performing git pull." + git pull || exit 3 + else + echo "Repository is already up to date." + fi + fi + + # Pull the latest images and rebuild the containers + echo "Pulling docker images and rebuilding containers." + docker-compose pull && docker-compose up -d --build --force-recreate || exit 1 + + # Additional command for the 'nextcloud' directory + if [ "$(basename "$dir")" == "nextcloud" ]; then + echo "Updating Nextcloud apps." + docker-compose exec -T -u www-data application /var/www/html/occ app:update --all || exit 2 + fi + cd - > /dev/null + fi +done diff --git a/roles/system-pacman/tasks/main.yml b/roles/update-pacman/tasks/main.yml similarity index 100% rename from roles/system-pacman/tasks/main.yml rename to roles/update-pacman/tasks/main.yml diff --git a/roles/update/meta/README.md b/roles/update/meta/README.md new file mode 100644 index 00000000..4af0fe38 --- /dev/null +++ b/roles/update/meta/README.md @@ -0,0 +1,2 @@ +# update +starts all of the different system update roles based on conditions \ No newline at end of file diff --git a/roles/update/meta/main.yml b/roles/update/meta/main.yml new file mode 100644 index 00000000..f24730d4 --- /dev/null +++ b/roles/update/meta/main.yml @@ -0,0 +1,10 @@ +tasks: + - name: "Check if {{path_docker_compose_files}} directory exists" + stat: + path: {{path_docker_compose_files}} + register: docker_compose_directory_stat + +roles: + - { role: update-pacman, when: ansible_distribution == 'Archlinux' } + - { role: update-apt, when: ansible_distribution == "Debian" } + - { role: update-docker, when: docker_compose_directory_stat.stat.exists } \ No newline at end of file