Matrix Docker Ansible eploy
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.
 
 

93 lines
3.2 KiB

  1. ---
  2. # Pre-checks
  3. - name: Fail if Postgres not enabled
  4. ansible.builtin.fail:
  5. msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot run vacuum."
  6. when: "not matrix_postgres_enabled | bool"
  7. # Defaults
  8. - name: Set postgres_start_wait_time, if not provided
  9. ansible.builtin.set_fact:
  10. postgres_start_wait_time: 15
  11. when: "postgres_start_wait_time | default('') == ''"
  12. - name: Set postgres_vacuum_wait_time, if not provided
  13. ansible.builtin.set_fact:
  14. postgres_vacuum_wait_time: "{{ 7 * 86400 }}"
  15. when: "postgres_vacuum_wait_time | default('') == ''"
  16. # Actual vacuuming work
  17. - name: Ensure matrix-postgres is started
  18. ansible.builtin.service:
  19. name: matrix-postgres
  20. state: started
  21. daemon_reload: true
  22. - name: Wait a bit, so that Postgres can start
  23. ansible.builtin.wait_for:
  24. timeout: "{{ postgres_start_wait_time }}"
  25. delegate_to: 127.0.0.1
  26. become: false
  27. - ansible.builtin.import_tasks: tasks/detect_existing_postgres_version.yml
  28. - name: Abort, if no existing Postgres version detected
  29. ansible.builtin.fail:
  30. msg: "Could not find existing Postgres installation"
  31. when: "not matrix_postgres_detected_existing | bool"
  32. - name: Generate Postgres database vacuum command
  33. ansible.builtin.set_fact:
  34. matrix_postgres_vacuum_command: >-
  35. {{ matrix_host_command_docker }} run --rm --name matrix-postgres-synapse-vacuum
  36. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  37. --cap-drop=ALL
  38. --network={{ matrix_docker_network }}
  39. --env-file={{ matrix_postgres_base_path }}/env-postgres-psql
  40. {{ matrix_postgres_docker_image_latest }}
  41. psql -v ON_ERROR_STOP=1 -h matrix-postgres {{ matrix_synapse_database_database }} -c 'VACUUM FULL VERBOSE'
  42. - name: Note about Postgres vacuum alternative
  43. ansible.builtin.debug:
  44. msg: >-
  45. Running vacuum with the following Postgres ansible.builtin.command: `{{ matrix_postgres_vacuum_command }}`.
  46. If this crashes, you can stop all processes (`systemctl stop matrix-*`),
  47. start Postgres only (`systemctl start matrix-postgres`)
  48. and manually run the above command directly on the server.
  49. - name: Populate service facts
  50. ansible.builtin.service_facts:
  51. - ansible.builtin.set_fact:
  52. 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' }}"
  53. - name: Ensure matrix-synapse is stopped
  54. ansible.builtin.service:
  55. name: matrix-synapse
  56. state: stopped
  57. daemon_reload: true
  58. - name: Run Postgres vacuum command
  59. ansible.builtin.command: "{{ matrix_postgres_vacuum_command }}"
  60. async: "{{ postgres_vacuum_wait_time }}"
  61. poll: 10
  62. register: matrix_postgres_synapse_vacuum_result
  63. failed_when: not matrix_postgres_synapse_vacuum_result.finished
  64. changed_when: matrix_postgres_synapse_vacuum_result.finished and matrix_postgres_synapse_vacuum_result.rc == 0
  65. # Intentionally show the results
  66. - ansible.builtin.debug: var="matrix_postgres_synapse_vacuum_result"
  67. - name: Ensure matrix-synapse is started, if it previously was
  68. ansible.builtin.service:
  69. name: matrix-synapse
  70. state: started
  71. daemon_reload: true
  72. when: "matrix_postgres_synapse_was_running | bool"