mirror of
https://github.com/spantaleev/matrix-docker-ansible-deploy.git
synced 2025-12-26 01:32:22 +03:00
Move roles/matrix* to roles/custom/matrix*
This paves the way for installing other roles into `roles/galaxy` using `ansible-galaxy`, similar to how it's done in: - https://github.com/spantaleev/gitea-docker-ansible-deploy - https://github.com/spantaleev/nextcloud-docker-ansible-deploy In the near future, we'll be removing a lot of the shared role code from here and using upstream roles for it. Some of the core `matrix-*` roles have already been extracted out into other reusable roles: - https://github.com/devture/com.devture.ansible.role.postgres - https://github.com/devture/com.devture.ansible.role.systemd_docker_base - https://github.com/devture/com.devture.ansible.role.timesync - https://github.com/devture/com.devture.ansible.role.vars_preserver - https://github.com/devture/com.devture.ansible.role.playbook_runtime_messages - https://github.com/devture/com.devture.ansible.role.playbook_help We just need to migrate to those.
This commit is contained in:
96
roles/custom/matrix-postgres/tasks/run_vacuum.yml
Normal file
96
roles/custom/matrix-postgres/tasks/run_vacuum.yml
Normal file
@@ -0,0 +1,96 @@
|
||||
---
|
||||
|
||||
# Pre-checks
|
||||
|
||||
- name: Fail if Postgres not enabled
|
||||
ansible.builtin.fail:
|
||||
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot run vacuum."
|
||||
when: "not matrix_postgres_enabled | bool"
|
||||
|
||||
|
||||
# Defaults
|
||||
|
||||
- name: Set postgres_start_wait_time, if not provided
|
||||
ansible.builtin.set_fact:
|
||||
postgres_start_wait_time: 15
|
||||
when: "postgres_start_wait_time | default('') == ''"
|
||||
|
||||
- name: Set postgres_vacuum_wait_time, if not provided
|
||||
ansible.builtin.set_fact:
|
||||
postgres_vacuum_wait_time: "{{ 7 * 86400 }}"
|
||||
when: "postgres_vacuum_wait_time | default('') == ''"
|
||||
|
||||
|
||||
# Actual vacuuming work
|
||||
|
||||
- name: Ensure matrix-postgres is started
|
||||
ansible.builtin.service:
|
||||
name: matrix-postgres
|
||||
state: started
|
||||
daemon_reload: true
|
||||
register: matrix_postgres_vacuum_start_result
|
||||
|
||||
- name: Wait a bit, so that Postgres can start
|
||||
when: matrix_postgres_vacuum_start_result.changed | bool
|
||||
ansible.builtin.wait_for:
|
||||
timeout: "{{ postgres_start_wait_time }}"
|
||||
delegate_to: 127.0.0.1
|
||||
become: false
|
||||
|
||||
- ansible.builtin.import_tasks: tasks/detect_existing_postgres_version.yml
|
||||
|
||||
- name: Abort, if no existing Postgres version detected
|
||||
ansible.builtin.fail:
|
||||
msg: "Could not find existing Postgres installation"
|
||||
when: "not matrix_postgres_detected_existing | bool"
|
||||
|
||||
- name: Generate Postgres database vacuum command
|
||||
ansible.builtin.set_fact:
|
||||
matrix_postgres_vacuum_command: >-
|
||||
{{ matrix_host_command_docker }} run --rm --name matrix-postgres-synapse-vacuum
|
||||
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
|
||||
--cap-drop=ALL
|
||||
--network={{ matrix_docker_network }}
|
||||
--env-file={{ matrix_postgres_base_path }}/env-postgres-psql
|
||||
{{ matrix_postgres_docker_image_latest }}
|
||||
psql -v ON_ERROR_STOP=1 -h matrix-postgres {{ matrix_synapse_database_database }} -c 'VACUUM FULL VERBOSE'
|
||||
|
||||
- name: Note about Postgres vacuum alternative
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
Running vacuum with the following Postgres ansible.builtin.command: `{{ matrix_postgres_vacuum_command }}`.
|
||||
If this crashes, you can stop all processes (`systemctl stop matrix-*`),
|
||||
start Postgres only (`systemctl start matrix-postgres`)
|
||||
and manually run the above command directly on the server.
|
||||
|
||||
- name: Populate service facts
|
||||
ansible.builtin.service_facts:
|
||||
|
||||
- ansible.builtin.set_fact:
|
||||
matrix_postgres_synapse_was_running: "{{ ansible_facts.services['matrix-synapse.service'] | default(none) is not none and ansible_facts.services['matrix-synapse.service'].state == 'running' }}"
|
||||
|
||||
- name: Ensure services are stopped
|
||||
ansible.builtin.service:
|
||||
name: "{{ item }}"
|
||||
state: stopped
|
||||
daemon_reload: true
|
||||
with_items: "{{ matrix_postgres_systemd_services_to_stop_for_maintenance_list }}"
|
||||
|
||||
- name: Run Postgres vacuum command
|
||||
ansible.builtin.command: "{{ matrix_postgres_vacuum_command }}"
|
||||
async: "{{ postgres_vacuum_wait_time }}"
|
||||
poll: 10
|
||||
register: matrix_postgres_synapse_vacuum_result
|
||||
failed_when: not matrix_postgres_synapse_vacuum_result.finished or matrix_postgres_synapse_vacuum_result.rc != 0
|
||||
changed_when: matrix_postgres_synapse_vacuum_result.finished and matrix_postgres_synapse_vacuum_result.rc == 0
|
||||
|
||||
# Intentionally show the results
|
||||
- ansible.builtin.debug:
|
||||
var: "matrix_postgres_synapse_vacuum_result"
|
||||
|
||||
- name: Ensure services are started
|
||||
ansible.builtin.service:
|
||||
name: "{{ item }}"
|
||||
state: started
|
||||
daemon_reload: true
|
||||
with_items: "{{ matrix_postgres_systemd_services_to_stop_for_maintenance_list }}"
|
||||
Reference in New Issue
Block a user