From 77fb33f5d5568d31da0f3160de59e3052dc9796d Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Tue, 3 Mar 2020 18:05:03 -0600 Subject: [PATCH] Restart gitea more cleaner Gerrit replication plugin is good about retrying replication if its connectivity to the remote fails. It however thinks everything is happy if it can connect and push even when gitea-web isn't running. Make the whole replication system happier by stopping gitea-ssh before other services and starting it after other services. This way gerrit should fail to replicate until gitea is ready for it to ssh in. Change-Id: I3440d8dd8a01a3aaf5d18c9c2ca48e7ead63856f --- playbooks/roles/gitea/tasks/main.yaml | 43 ++++++++++++++++--- .../gitea/templates/docker-compose.yaml.j2 | 1 + 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/playbooks/roles/gitea/tasks/main.yaml b/playbooks/roles/gitea/tasks/main.yaml index 6c19bdb140..8226637555 100644 --- a/playbooks/roles/gitea/tasks/main.yaml +++ b/playbooks/roles/gitea/tasks/main.yaml @@ -34,13 +34,42 @@ shell: cmd: docker-compose pull chdir: /etc/gitea-docker/ -- name: Run docker-compose up - shell: - cmd: docker-compose up -d --timeout 60 - chdir: /etc/gitea-docker/ -- name: Run docker prune to cleanup unneeded images - shell: - cmd: docker image prune -f + register: docker_compose_pull + +- name: Stop/Start gitea safely for Gerrit replication + when: "'Downloaded newer image' in docker_compose_pull.stdout" + block: + - name: Run docker-compose stop + shell: + cmd: docker-compose stop --timeout 60 + chdir: /etc/gitea-docker/ + - name: Run docker-compose up mariadb gitea-web + shell: + cmd: docker-compose up -d --timeout 60 mariadb gitea-web + chdir: /etc/gitea-docker/ + + # We wait here for the main gitea service to start before starting + # the ssh service. This is friendly to gerrit replication. + - name: Wait until the web service is sufficiently up to start ssh + uri: + url: "https://localhost:3000/api/v1/users/root" + validate_certs: false + status_code: 200, 404 + register: root_user_check + delay: 1 + retries: 300 + until: root_user_check and root_user_check.status in (200, 404) + + - name: Run docker-compose up gitea-ssh + shell: + cmd: docker-compose up -d --timeout 60 gitea-ssh + chdir: /etc/gitea-docker/ + - name: Run docker prune to cleanup unneeded images + shell: + cmd: docker image prune -f + +# User management outside of service bringup to avoid confusion between +# the two stages. - name: Check if root user exists uri: url: "https://localhost:3000/api/v1/users/root" diff --git a/playbooks/roles/gitea/templates/docker-compose.yaml.j2 b/playbooks/roles/gitea/templates/docker-compose.yaml.j2 index 0ae57b8276..1dab97f1ff 100644 --- a/playbooks/roles/gitea/templates/docker-compose.yaml.j2 +++ b/playbooks/roles/gitea/templates/docker-compose.yaml.j2 @@ -35,6 +35,7 @@ services: gitea-ssh: depends_on: - mariadb + - gitea-web environment: - SSH_LISTEN_PORT=222 image: docker.io/opendevorg/gitea-openssh