From 2a7c755a08f0b89c287be4a5b8715f44850345f4 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Fri, 24 Apr 2020 17:25:41 -0500 Subject: [PATCH] Rework zuul start/stop/restart playbooks for docker If we need to start and stop, it's best to use playbooks. We already have tasks files with start commands in each role, so put the stop commands into similar task files. Make the restart playbook import_playbook the stop and start playbooks to reduce divergence. Use the graceful shutdown pattern from the gerrit docker-compose to stop the zuul scheduler. Change-Id: Ia20124553821f4b41186bce6ba2bff6ca2333a99 --- playbooks/roles/zuul-executor/tasks/stop.yaml | 12 ++ playbooks/roles/zuul-merger/tasks/stop.yaml | 6 + .../roles/zuul-scheduler/tasks/stop.yaml | 6 + playbooks/roles/zuul-web/tasks/stop.yaml | 6 + playbooks/start-mergers-executors.yaml | 9 ++ playbooks/stop-mergers-executors.yaml | 9 ++ playbooks/zuul_restart.yaml | 109 +----------------- playbooks/zuul_start.yaml | 34 ++---- playbooks/zuul_stop.yaml | 59 ++-------- 9 files changed, 66 insertions(+), 184 deletions(-) create mode 100644 playbooks/roles/zuul-executor/tasks/stop.yaml create mode 100644 playbooks/roles/zuul-merger/tasks/stop.yaml create mode 100644 playbooks/roles/zuul-scheduler/tasks/stop.yaml create mode 100644 playbooks/roles/zuul-web/tasks/stop.yaml create mode 100644 playbooks/start-mergers-executors.yaml create mode 100644 playbooks/stop-mergers-executors.yaml diff --git a/playbooks/roles/zuul-executor/tasks/stop.yaml b/playbooks/roles/zuul-executor/tasks/stop.yaml new file mode 100644 index 0000000000..7916800895 --- /dev/null +++ b/playbooks/roles/zuul-executor/tasks/stop.yaml @@ -0,0 +1,12 @@ +- name: Stop Zuul Executor + service: + name: zuul-executor + state: stopped + become: true + become_user: root + +- name: Wait for (3h10m) to stop Zuul Executor + wait_for: + path: /var/run/zuul/executor.pid + state: absent + timeout: 11400 diff --git a/playbooks/roles/zuul-merger/tasks/stop.yaml b/playbooks/roles/zuul-merger/tasks/stop.yaml new file mode 100644 index 0000000000..ff56326ad7 --- /dev/null +++ b/playbooks/roles/zuul-merger/tasks/stop.yaml @@ -0,0 +1,6 @@ +- name: Stop Zuul Merger + shell: + cmd: docker-compose down + chdir: /etc/zuul-merger + become: true + become_user: root diff --git a/playbooks/roles/zuul-scheduler/tasks/stop.yaml b/playbooks/roles/zuul-scheduler/tasks/stop.yaml new file mode 100644 index 0000000000..f846ab1305 --- /dev/null +++ b/playbooks/roles/zuul-scheduler/tasks/stop.yaml @@ -0,0 +1,6 @@ +- name: Stop Zuul Scheduler + shell: + cmd: docker-compose down + chdir: /etc/zuul-scheduler + become: true + become_user: root diff --git a/playbooks/roles/zuul-web/tasks/stop.yaml b/playbooks/roles/zuul-web/tasks/stop.yaml new file mode 100644 index 0000000000..0108ce7f2a --- /dev/null +++ b/playbooks/roles/zuul-web/tasks/stop.yaml @@ -0,0 +1,6 @@ +- name: Stop Zuul Web and Finger Gateway + shell: + cmd: docker-compose down + chdir: /etc/zuul-web + become: true + become_user: root diff --git a/playbooks/start-mergers-executors.yaml b/playbooks/start-mergers-executors.yaml new file mode 100644 index 0000000000..1867611a6f --- /dev/null +++ b/playbooks/start-mergers-executors.yaml @@ -0,0 +1,9 @@ +- hosts: zuul-merger + tasks: + - shell: + cmd: docker-compose up -d + chdir: /etc/zuul-merger + +- hosts: zuul-executor + tasks: + - shell: systemctl start zuul-executor diff --git a/playbooks/stop-mergers-executors.yaml b/playbooks/stop-mergers-executors.yaml new file mode 100644 index 0000000000..81a3d4e1f4 --- /dev/null +++ b/playbooks/stop-mergers-executors.yaml @@ -0,0 +1,9 @@ +- hosts: zuul-merger + tasks: + - shell: + cmd: docker-compose down + chdir: /etc/zuul-merger + +- hosts: zuul-executor + tasks: + - shell: systemctl stop zuul-executor diff --git a/playbooks/zuul_restart.yaml b/playbooks/zuul_restart.yaml index 8abef887ef..b529be958c 100644 --- a/playbooks/zuul_restart.yaml +++ b/playbooks/zuul_restart.yaml @@ -1,109 +1,4 @@ # Run this with "-f 20" -- hosts: 'zuul-scheduler:!disabled' - any_errors_fatal: true - tasks: - - name: Stop Zuul Scheduler - service: - name: zuul-scheduler - state: stopped - become: true - become_user: root - - name: Stop Zuul Web - service: - name: zuul-web - state: stopped - become: true - become_user: root - - name: Stop Zuul Finger Gateway - service: - name: zuul-fingergw - state: stopped - become: true - become_user: root - - name: Wait for (3h10m) to stop Zuul Scheduler - wait_for: - path: /var/run/zuul/scheduler.pid - state: absent - timeout: 11400 - - name: Wait for (3h10m) to stop Zuul Web - wait_for: - path: /var/run/zuul/web.pid - state: absent - timeout: 11400 - - name: Wait for (3h10m) to stop Zuul Finger Gateway - wait_for: - path: /var/run/zuul/fingergw.pid - state: absent - timeout: 11400 - -- hosts: 'zuul-merger:!disabled' - tasks: - - name: Stop Zuul Mergers - service: - name: zuul-merger - state: stopped - become: true - become_user: root - -- hosts: 'zuul-executor:!disabled' - tasks: - - name: Stop Zuul Executors - service: - name: zuul-executor - state: stopped - become: true - become_user: root - -- hosts: 'zuul-scheduler:!disabled' - tasks: - - name: Start Zuul Scheduler - service: - name: zuul-scheduler - state: started - become: true - become_user: root - - name: Start Zuul Web - service: - name: zuul-web - state: started - become: true - become_user: root - - name: Start Zuul Finger Gateway - service: - name: zuul-fingergw - state: started - become: true - become_user: root - -- hosts: 'zuul-merger:!disabled' - tasks: - - name: Wait for (3h10m) to stop Zuul Mergers - wait_for: - path: /var/run/zuul/merger.pid - state: absent - timeout: 11400 - - name: Start Zuul Mergers - service: - name: zuul-merger - state: started - become: true - become_user: root - -- hosts: 'zuul-executor:!disabled' - tasks: - - name: Wait for (3h10m) to stop Zuul Executors - wait_for: - path: /var/run/zuul/executor.pid - state: absent - timeout: 11400 - - name: Update the ansible installations - command: zuul-manage-ansible -u - environment: - ANSIBLE_EXTRA_PACKAGES: gear - - name: Start Zuul Executors - service: - name: zuul-executor - state: started - become: true - become_user: root +- import_playbook: zuul_stop.yaml +- import_playbook: zuul_start.yaml diff --git a/playbooks/zuul_start.yaml b/playbooks/zuul_start.yaml index 537edb8789..8865a6d996 100644 --- a/playbooks/zuul_start.yaml +++ b/playbooks/zuul_start.yaml @@ -2,39 +2,21 @@ - hosts: 'zuul-scheduler:!disabled' tasks: - - name: Start Zuul Scheduler - service: + - include_role: name: zuul-scheduler - state: started - become: true - become_user: root - - name: Stop Zuul Web - service: + tasks_from: start + - include_role: name: zuul-web - state: started - become: true - become_user: root - - name: Stop Zuul Finger Gateway - service: - name: zuul-fingergw - state: started - become: true - become_user: root + tasks_from: start - hosts: 'zuul-merger:!disabled' tasks: - - name: Start Zuul Mergers - service: + - include_role: name: zuul-merger - state: started - become: true - become_user: root + tasks_from: start - hosts: 'zuul-executor:!disabled' tasks: - - name: Start Zuul Executors - service: + - include_role: name: zuul-executor - state: started - become: true - become_user: root + tasks_from: start diff --git a/playbooks/zuul_stop.yaml b/playbooks/zuul_stop.yaml index 09ea8ce5e7..58aeaa42bb 100644 --- a/playbooks/zuul_stop.yaml +++ b/playbooks/zuul_stop.yaml @@ -3,64 +3,21 @@ - hosts: 'zuul-scheduler:!disabled' any_errors_fatal: true tasks: - - name: Stop Zuul Scheduler - service: + - include_role: name: zuul-scheduler - state: stopped - become: true - become_user: root - - name: Stop Zuul Web - service: + tasks_from: stop + - include_role: name: zuul-web - state: stopped - become: true - become_user: root - - name: Stop Zuul Finger Gateway - service: - name: zuul-fingergw - state: stopped - become: true - become_user: root - - name: Wait for (3h10m) to stop Zuul Scheduler - wait_for: - path: /var/run/zuul/scheduler.pid - state: absent - timeout: 11400 - - name: Wait for (3h10m) to stop Zuul Web - wait_for: - path: /var/run/zuul/web.pid - state: absent - timeout: 11400 - - name: Wait for (3h10m) to stop Zuul Finger Gateway - wait_for: - path: /var/run/zuul/fingergw.pid - state: absent - timeout: 11400 + tasks_from: stop - hosts: 'zuul-merger:!disabled' tasks: - - name: Stop Zuul Merger - service: + - include_role: name: zuul-merger - state: stopped - become: true - become_user: root - - name: Wait for (3h10m) to stop Zuul Merger - wait_for: - path: /var/run/zuul/merger.pid - state: absent - timeout: 11400 + tasks_from: stop - hosts: 'zuul-executor:!disabled' tasks: - - name: Stop Zuul Executor - service: + - include_role: name: zuul-executor - state: stopped - become: true - become_user: root - - name: Wait for (3h10m) to stop Zuul Executor - wait_for: - path: /var/run/zuul/executor.pid - state: absent - timeout: 11400 + tasks_from: stop