From dbfa806092e3ee933ee895d211e5dd1dd40bd4ef Mon Sep 17 00:00:00 2001 From: Alex Demidoff Date: Tue, 12 Dec 2023 23:28:10 +0000 Subject: [PATCH] PMM-12530 use a different become method for supervisorctl --- build/ansible/pmm/post-build-actions.yml | 13 +++++++++---- build/ansible/roles/pmm-images/tasks/main.yml | 2 +- build/docker/server/Dockerfile.el9 | 2 ++ .../playbook/tasks/roles/dashboards/tasks/main.yml | 14 ++++++-------- .../playbook/tasks/roles/postgres/tasks/backup.yml | 6 +++++- .../tasks/roles/postgres/tasks/restore.yml | 7 ++++++- update/ansible/playbook/tasks/update.yml | 10 +++++++++- 7 files changed, 38 insertions(+), 16 deletions(-) diff --git a/build/ansible/pmm/post-build-actions.yml b/build/ansible/pmm/post-build-actions.yml index 769531032e..8af4c159c6 100644 --- a/build/ansible/pmm/post-build-actions.yml +++ b/build/ansible/pmm/post-build-actions.yml @@ -81,15 +81,18 @@ - name: See which service configs changed debug: var=reread_result.stdout_lines - - name: Stop pmm-managed before deleting the database EL9 + - name: Stop pmm-managed before deleting the database when: - ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux' - ansible_distribution_major_version == '9' supervisorctl: name: pmm-managed state: stopped + become: true + become_user: pmm + become_method: su - - name: Remove pmm-managed database EL9 + - name: Remove pmm-managed database when: - ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux' - ansible_distribution_major_version == '9' @@ -123,8 +126,10 @@ path: /var/cache/dnf - name: Cleanup build logs and data - file: path={{ item }} state=absent - with_items: + file: + path: "{{ item }}" + state: absent + loop: - /srv/logs - /tmp/RPMS - /var/log/dnf.log diff --git a/build/ansible/roles/pmm-images/tasks/main.yml b/build/ansible/roles/pmm-images/tasks/main.yml index e8cce7e2ed..a88e3699ae 100644 --- a/build/ansible/roles/pmm-images/tasks/main.yml +++ b/build/ansible/roles/pmm-images/tasks/main.yml @@ -170,7 +170,7 @@ include_role: name: supervisord-init -- name: PMM | Enable repo for pmm-client +- name: Enable repo for pmm-client command: percona-release enable {{ pmm_client_repos }} - name: Install pmm-client diff --git a/build/docker/server/Dockerfile.el9 b/build/docker/server/Dockerfile.el9 index a7ed9285a5..60ebd11802 100644 --- a/build/docker/server/Dockerfile.el9 +++ b/build/docker/server/Dockerfile.el9 @@ -41,5 +41,7 @@ RUN ansible-playbook -vvv -i 'localhost,' -c local /opt/ansible/pmm-docker/main. && ansible-playbook -vvv -i 'localhost,' -c local /opt/ansible/pmm/post-build-actions.yml COPY entrypoint.sh /opt/entrypoint.sh + HEALTHCHECK --interval=3s --timeout=2s --start-period=10s --retries=3 CMD curl -f http://127.0.0.1:8080/v1/readyz || exit 1 + CMD ["/opt/entrypoint.sh"] diff --git a/update/ansible/playbook/tasks/roles/dashboards/tasks/main.yml b/update/ansible/playbook/tasks/roles/dashboards/tasks/main.yml index 3e1745e998..164f1b93cd 100644 --- a/update/ansible/playbook/tasks/roles/dashboards/tasks/main.yml +++ b/update/ansible/playbook/tasks/roles/dashboards/tasks/main.yml @@ -6,7 +6,7 @@ depth: 2 file_type: directory -- name: Delete redundant dist folders +- name: Delete older plugins file: path: "/srv/grafana/plugins/{{ item['path'].split('/')[-1] }}" state: absent @@ -26,14 +26,12 @@ mode: 0775 recurse: yes -- name: Restart grafana with new plugins EL9 +# TODO: fix the race condition. +- name: Restart grafana with new plugins supervisorctl: name: grafana state: restarted become: true - when: - - ansible_distribution == 'OracleLinux' or ansible_distribution == 'AlmaLinux' - - ansible_distribution_major_version == '9' - ignore_errors: true - # TODO: fix the race condition. - # We generate grafana supervisor config in pmm-managed and it may not exist at this stage + become_user: pmm + become_method: su + # ignore_errors: true diff --git a/update/ansible/playbook/tasks/roles/postgres/tasks/backup.yml b/update/ansible/playbook/tasks/roles/postgres/tasks/backup.yml index 96f05d5df9..8ea9868fba 100644 --- a/update/ansible/playbook/tasks/roles/postgres/tasks/backup.yml +++ b/update/ansible/playbook/tasks/roles/postgres/tasks/backup.yml @@ -28,6 +28,8 @@ - pmm-agent - postgresql become: true + become_user: pmm + become_method: su - name: Run Postgres database without supervisor command: /usr/pgsql-14/bin/pg_ctl start -D /srv/postgres14 -o "-c logging_collector=off" @@ -63,6 +65,8 @@ - postgresql - pmm-managed - pmm-agent - become: true + become: true + become_user: pmm + become_method: su when: is_supervisor_running diff --git a/update/ansible/playbook/tasks/roles/postgres/tasks/restore.yml b/update/ansible/playbook/tasks/roles/postgres/tasks/restore.yml index f29b16e874..91cc2f0bc4 100644 --- a/update/ansible/playbook/tasks/roles/postgres/tasks/restore.yml +++ b/update/ansible/playbook/tasks/roles/postgres/tasks/restore.yml @@ -28,6 +28,8 @@ - pmm-agent - postgresql become: true + become_user: pmm + become_method: su - name: Run Postgres database without supervisor command: /usr/pgsql-14/bin/pg_ctl start -D /srv/postgres @@ -68,6 +70,9 @@ - postgresql - pmm-managed - pmm-agent - become: true + become: true + become_user: pmm + become_method: su + when: is_supervisor_running diff --git a/update/ansible/playbook/tasks/update.yml b/update/ansible/playbook/tasks/update.yml index b4ce3d7a84..5a765f4810 100644 --- a/update/ansible/playbook/tasks/update.yml +++ b/update/ansible/playbook/tasks/update.yml @@ -51,7 +51,8 @@ path: /run/supervisor/supervisor.sock register: is_supervisor_running - - name: Start supervisord for docker + # During build time, this will be the first start of supervisord. + - name: Start supervisord when: - not is_supervisor_running.stat.exists shell: supervisord -c /etc/supervisord.conf & @@ -70,6 +71,9 @@ # why we do reread + stop/remove/add instead of using supervisorctl Ansible module. - name: Reread supervisord configuration command: supervisorctl reread + become: true + become_user: pmm + become_method: su register: reread_result changed_when: "'No config updates to processes' not in reread_result.stdout" @@ -79,6 +83,8 @@ - name: Restart pmm-managed command: "supervisorctl {{ item }} pmm-managed" become: true + become_user: pmm + become_method: su loop: - stop - remove @@ -102,6 +108,8 @@ - name: Restart services command: supervisorctl {{ item.1 }} {{ item.0 }} become: true + become_user: pmm + become_method: su changed_when: true with_nested: - - nginx