You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
3.5 KiB
97 lines
3.5 KiB
5 years ago
|
---
|
||
|
|
||
|
# Pre-checks
|
||
|
|
||
|
- name: Fail if Postgres not enabled
|
||
2 years ago
|
ansible.builtin.fail:
|
||
5 years ago
|
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot run vacuum."
|
||
2 years ago
|
when: "not matrix_postgres_enabled | bool"
|
||
5 years ago
|
|
||
|
|
||
|
# Defaults
|
||
|
|
||
|
- name: Set postgres_start_wait_time, if not provided
|
||
2 years ago
|
ansible.builtin.set_fact:
|
||
5 years ago
|
postgres_start_wait_time: 15
|
||
2 years ago
|
when: "postgres_start_wait_time | default('') == ''"
|
||
5 years ago
|
|
||
|
- name: Set postgres_vacuum_wait_time, if not provided
|
||
2 years ago
|
ansible.builtin.set_fact:
|
||
5 years ago
|
postgres_vacuum_wait_time: "{{ 7 * 86400 }}"
|
||
2 years ago
|
when: "postgres_vacuum_wait_time | default('') == ''"
|
||
5 years ago
|
|
||
|
|
||
|
# Actual vacuuming work
|
||
|
|
||
|
- name: Ensure matrix-postgres is started
|
||
2 years ago
|
ansible.builtin.service:
|
||
5 years ago
|
name: matrix-postgres
|
||
|
state: started
|
||
3 years ago
|
daemon_reload: true
|
||
2 years ago
|
register: matrix_postgres_vacuum_start_result
|
||
5 years ago
|
|
||
2 years ago
|
- name: Wait a bit, so that Postgres can start
|
||
|
when: matrix_postgres_vacuum_start_result.changed | bool
|
||
2 years ago
|
ansible.builtin.wait_for:
|
||
5 years ago
|
timeout: "{{ postgres_start_wait_time }}"
|
||
|
delegate_to: 127.0.0.1
|
||
|
become: false
|
||
|
|
||
2 years ago
|
- ansible.builtin.import_tasks: tasks/detect_existing_postgres_version.yml
|
||
5 years ago
|
|
||
|
- name: Abort, if no existing Postgres version detected
|
||
2 years ago
|
ansible.builtin.fail:
|
||
5 years ago
|
msg: "Could not find existing Postgres installation"
|
||
2 years ago
|
when: "not matrix_postgres_detected_existing | bool"
|
||
5 years ago
|
|
||
|
- name: Generate Postgres database vacuum command
|
||
2 years ago
|
ansible.builtin.set_fact:
|
||
5 years ago
|
matrix_postgres_vacuum_command: >-
|
||
5 years ago
|
{{ matrix_host_command_docker }} run --rm --name matrix-postgres-synapse-vacuum
|
||
5 years ago
|
--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
|
||
2 years ago
|
ansible.builtin.debug:
|
||
5 years ago
|
msg: >-
|
||
2 years ago
|
Running vacuum with the following Postgres ansible.builtin.command: `{{ matrix_postgres_vacuum_command }}`.
|
||
5 years ago
|
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
|
||
2 years ago
|
ansible.builtin.service_facts:
|
||
5 years ago
|
|
||
2 years ago
|
- ansible.builtin.set_fact:
|
||
2 years ago
|
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' }}"
|
||
5 years ago
|
|
||
2 years ago
|
- name: Ensure services are stopped
|
||
2 years ago
|
ansible.builtin.service:
|
||
2 years ago
|
name: "{{ item }}"
|
||
5 years ago
|
state: stopped
|
||
3 years ago
|
daemon_reload: true
|
||
2 years ago
|
with_items: "{{ matrix_postgres_systemd_services_to_stop_for_maintenance_list }}"
|
||
5 years ago
|
|
||
|
- name: Run Postgres vacuum command
|
||
2 years ago
|
ansible.builtin.command: "{{ matrix_postgres_vacuum_command }}"
|
||
5 years ago
|
async: "{{ postgres_vacuum_wait_time }}"
|
||
|
poll: 10
|
||
|
register: matrix_postgres_synapse_vacuum_result
|
||
2 years ago
|
failed_when: not matrix_postgres_synapse_vacuum_result.finished or matrix_postgres_synapse_vacuum_result.rc != 0
|
||
2 years ago
|
changed_when: matrix_postgres_synapse_vacuum_result.finished and matrix_postgres_synapse_vacuum_result.rc == 0
|
||
5 years ago
|
|
||
|
# Intentionally show the results
|
||
2 years ago
|
- ansible.builtin.debug:
|
||
|
var: "matrix_postgres_synapse_vacuum_result"
|
||
5 years ago
|
|
||
2 years ago
|
- name: Ensure services are started
|
||
2 years ago
|
ansible.builtin.service:
|
||
2 years ago
|
name: "{{ item }}"
|
||
5 years ago
|
state: started
|
||
3 years ago
|
daemon_reload: true
|
||
2 years ago
|
with_items: "{{ matrix_postgres_systemd_services_to_stop_for_maintenance_list }}"
|