From eec60a2cb987289d0f43aa72cd05a04fc6ce6ab0 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Wed, 16 Aug 2023 00:09:09 +0000 Subject: [PATCH] Restart Mailman 3 containers when configs change Add a handler for restarting Mailman 3 containers if they're up, and notify it from all of the copy tasks for configuration files. Check for the uwsgi processes that Django runs under to determine whether the containers are running. Change-Id: I73be59be773fdde100999c7872520aab1d9e2066 --- playbooks/roles/mailman3/handlers/main.yaml | 3 +++ .../roles/mailman3/handlers/restart_mailman.yaml | 15 +++++++++++++++ playbooks/roles/mailman3/tasks/main.yaml | 6 ++++++ 3 files changed, 24 insertions(+) create mode 100644 playbooks/roles/mailman3/handlers/restart_mailman.yaml diff --git a/playbooks/roles/mailman3/handlers/main.yaml b/playbooks/roles/mailman3/handlers/main.yaml index 18f5b3bbc9..b7b3aad496 100644 --- a/playbooks/roles/mailman3/handlers/main.yaml +++ b/playbooks/roles/mailman3/handlers/main.yaml @@ -7,3 +7,6 @@ service: name: apache2 state: reloaded + +- name: mailman restart containers + include_tasks: roles/mailman3/handlers/restart_mailman.yaml diff --git a/playbooks/roles/mailman3/handlers/restart_mailman.yaml b/playbooks/roles/mailman3/handlers/restart_mailman.yaml new file mode 100644 index 0000000000..9a8bc1b009 --- /dev/null +++ b/playbooks/roles/mailman3/handlers/restart_mailman.yaml @@ -0,0 +1,15 @@ +- name: mailman check for running containers + command: pgrep -f uwsgi + ignore_errors: yes + register: uwsgi_pids + +- name: mailman restart containers if running + # Also makes sure the containers weren't just restarted by an image update + when: uwsgi_pids.rc == 0 and "is up-to-date" in mailman_dcup.stdout + block: + - name: down containers + shell: + cmd: docker-compose -f /etc/mailman-compose/docker-compose.yaml down + - name: up containers + shell: + cmd: docker-compose -f /etc/mailman-compose/docker-compose.yaml up -d diff --git a/playbooks/roles/mailman3/tasks/main.yaml b/playbooks/roles/mailman3/tasks/main.yaml index 2ec20efadc..36eba320c1 100644 --- a/playbooks/roles/mailman3/tasks/main.yaml +++ b/playbooks/roles/mailman3/tasks/main.yaml @@ -43,6 +43,7 @@ owner: 100 group: 65533 mode: '0644' + notify: mailman restart containers - name: Ensure Mailman database volume directory exists file: @@ -76,6 +77,7 @@ owner: 100 group: 101 mode: '0644' + notify: mailman restart containers - name: Check for initial setup flag file stat: @@ -100,6 +102,7 @@ owner: 100 group: 101 mode: '0644' + notify: mailman restart containers - name: Copy our max_allowed_packet override config copy: @@ -108,6 +111,7 @@ owner: 999 group: 999 mode: '0644' + notify: mailman restart containers - name: Ensure /etc/mailman-compose directory file: @@ -120,6 +124,7 @@ src: docker-compose.yaml.j2 dest: /etc/mailman-compose/docker-compose.yaml mode: '0600' + notify: mailman restart containers - name: Run docker-compose pull shell: @@ -130,6 +135,7 @@ shell: cmd: docker-compose up -d chdir: /etc/mailman-compose/ + register: mailman_dcup - name: Run docker prune to cleanup unneeded images shell: