From d71b3a798d5030e28bcdd1d6f00ae82d128a480b Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Tue, 6 Sep 2022 13:10:52 -0700 Subject: [PATCH] Handle no running containers during zuul graceful stop The way the currently graceful stop tasks are written for zuul expects there to always be a running zuul container to exec into. There are situations where there may not be a running container in which case there is nothing to stop. Avoid this being an error by checking if the containers are running before execing into them. If no containers are running then we'll noop the docker exec step allowing the rest of the ansible tasks to continue. Change-Id: I6c47147a589ae12cc33e37e40e49673396d120f7 --- playbooks/roles/zuul-executor/tasks/graceful.yaml | 10 ++++++++++ playbooks/roles/zuul-merger/tasks/graceful.yaml | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/playbooks/roles/zuul-executor/tasks/graceful.yaml b/playbooks/roles/zuul-executor/tasks/graceful.yaml index 503253a9e0..71a6a4940f 100644 --- a/playbooks/roles/zuul-executor/tasks/graceful.yaml +++ b/playbooks/roles/zuul-executor/tasks/graceful.yaml @@ -1,9 +1,19 @@ +- name: Check if Zuul Executor containers are running + # It is possible they are stopped due to some external circumstance + command: + cmd: docker-compose ps -q + chdir: /etc/zuul-executor + become: true + become_user: root + register: executor_container_list - name: Gracefully stop Zuul Executor shell: cmd: docker-compose exec executor zuul-executor graceful chdir: /etc/zuul-executor become: true become_user: root + # Only run the docker exec command if a container is running + when: executor_container_list.stdout_lines | length > 0 - name: Wait for Zuul Executor to stop shell: cmd: docker-compose ps -q | xargs docker wait diff --git a/playbooks/roles/zuul-merger/tasks/graceful.yaml b/playbooks/roles/zuul-merger/tasks/graceful.yaml index 37da7ac8d0..72f7d4d705 100644 --- a/playbooks/roles/zuul-merger/tasks/graceful.yaml +++ b/playbooks/roles/zuul-merger/tasks/graceful.yaml @@ -1,9 +1,19 @@ +- name: Check if Zuul merger containers are running + # It is possible they are stopped due to some external circumstance + command: + cmd: docker-compose ps -q + chdir: /etc/zuul-merger + become: true + become_user: root + register: merger_container_list - name: Gracefully stop Zuul Merger shell: cmd: docker-compose exec merger zuul-merger stop chdir: /etc/zuul-merger become: true become_user: root + # Only run the docker exec command if a container is running + when: merger_container_list.stdout_lines | length > 0 - name: Wait for Zuul Merger to stop shell: cmd: docker-compose ps -q | xargs docker wait