Our graceful restart scripts were written for docker-compose which, unlike "docker", returns information about stopped containers in the output of the "ps" subcommand. Now that we are switching to the docker compose plugin, the ps subcommand apparently behaves more like the docker ps command. Update our scripts to include the "-a" argument which includes all containers. This works with both versions of compose. Change-Id: I950e07ba0cb514c32410a239d92075a11a27a839
43 lines
1.5 KiB
YAML
43 lines
1.5 KiB
YAML
- name: Check if Zuul merger containers are running
|
|
# It is possible they are stopped due to some external circumstance.
|
|
# NOTE: docker-compose ps -qa reports exited containers
|
|
command:
|
|
cmd: docker-compose ps -qa
|
|
chdir: /etc/zuul-merger
|
|
become: true
|
|
become_user: root
|
|
register: merger_container_list
|
|
- name: Gracefully stop Zuul Merger
|
|
shell:
|
|
cmd: docker-compose exec -T 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
|
|
register: zm_graceful
|
|
failed_when:
|
|
- zm_graceful.rc != 0
|
|
# There is a fun race with docker exec and shutting down the
|
|
# container running the exec. If the container is stopped while
|
|
# the exec is running then the command in the exec effectively gets
|
|
# kill -9'd and the docker exec command rc is 137. Since this
|
|
# should only happen when the container is stopped we proceed with
|
|
# the overall graceful shutdown.
|
|
- zm_graceful.rc != 137
|
|
# If the exec fails because the container is not running we continue.
|
|
- "'No container found' not in zm_graceful.stderr"
|
|
- name: Wait for Zuul Merger to stop
|
|
shell:
|
|
cmd: docker-compose ps -qa | xargs docker wait
|
|
chdir: /etc/zuul-merger
|
|
become: true
|
|
become_user: root
|
|
when: merger_container_list.stdout_lines | length > 0
|
|
- name: Down Zuul Merger containers
|
|
shell:
|
|
cmd: docker-compose down
|
|
chdir: /etc/zuul-merger
|
|
become: true
|
|
become_user: root
|