Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

97 строки
3.5 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. register: matrix_postgres_vacuum_start_result
  23. - name: Wait a bit, so that Postgres can start
  24. when: matrix_postgres_vacuum_start_result.changed | bool
  25. ansible.builtin.wait_for:
  26. timeout: "{{ postgres_start_wait_time }}"
  27. delegate_to: 127.0.0.1
  28. become: false
  29. - ansible.builtin.import_tasks: tasks/detect_existing_postgres_version.yml
  30. - name: Abort, if no existing Postgres version detected
  31. ansible.builtin.fail:
  32. msg: "Could not find existing Postgres installation"
  33. when: "not matrix_postgres_detected_existing | bool"
  34. - name: Generate Postgres database vacuum command
  35. ansible.builtin.set_fact:
  36. matrix_postgres_vacuum_command: >-
  37. {{ matrix_host_command_docker }} run --rm --name matrix-postgres-synapse-vacuum
  38. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  39. --cap-drop=ALL
  40. --network={{ matrix_docker_network }}
  41. --env-file={{ matrix_postgres_base_path }}/env-postgres-psql
  42. {{ matrix_postgres_docker_image_latest }}
  43. psql -v ON_ERROR_STOP=1 -h matrix-postgres {{ matrix_synapse_database_database }} -c 'VACUUM FULL VERBOSE'
  44. - name: Note about Postgres vacuum alternative
  45. ansible.builtin.debug:
  46. msg: >-
  47. Running vacuum with the following Postgres ansible.builtin.command: `{{ matrix_postgres_vacuum_command }}`.
  48. If this crashes, you can stop all processes (`systemctl stop matrix-*`),
  49. start Postgres only (`systemctl start matrix-postgres`)
  50. and manually run the above command directly on the server.
  51. - name: Populate service facts
  52. ansible.builtin.service_facts:
  53. - ansible.builtin.set_fact:
  54. 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' }}"
  55. - name: Ensure services are stopped
  56. ansible.builtin.service:
  57. name: "{{ item }}"
  58. state: stopped
  59. daemon_reload: true
  60. with_items: "{{ matrix_postgres_systemd_services_to_stop_for_maintenance_list }}"
  61. - name: Run Postgres vacuum command
  62. ansible.builtin.command: "{{ matrix_postgres_vacuum_command }}"
  63. async: "{{ postgres_vacuum_wait_time }}"
  64. poll: 10
  65. register: matrix_postgres_synapse_vacuum_result
  66. failed_when: not matrix_postgres_synapse_vacuum_result.finished or matrix_postgres_synapse_vacuum_result.rc != 0
  67. changed_when: matrix_postgres_synapse_vacuum_result.finished and matrix_postgres_synapse_vacuum_result.rc == 0
  68. # Intentionally show the results
  69. - ansible.builtin.debug:
  70. var: "matrix_postgres_synapse_vacuum_result"
  71. - name: Ensure services are started
  72. ansible.builtin.service:
  73. name: "{{ item }}"
  74. state: started
  75. daemon_reload: true
  76. with_items: "{{ matrix_postgres_systemd_services_to_stop_for_maintenance_list }}"