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

91 строка
2.8 KiB

  1. ---
  2. # Pre-checks
  3. - name: Fail if Postgres not enabled
  4. 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. 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. 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. service:
  19. name: matrix-postgres
  20. state: started
  21. daemon_reload: yes
  22. - name: Wait a bit, so that Postgres can start
  23. wait_for:
  24. timeout: "{{ postgres_start_wait_time }}"
  25. delegate_to: 127.0.0.1
  26. become: false
  27. - import_tasks: tasks/util/detect_existing_postgres_version.yml
  28. - name: Abort, if no existing Postgres version detected
  29. 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. 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. debug:
  44. msg: >-
  45. Running vacuum with the following Postgres 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. service_facts:
  51. - 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. service:
  55. name: matrix-synapse
  56. state: stopped
  57. daemon_reload: yes
  58. - name: Run Postgres vacuum command
  59. command: "{{ matrix_postgres_vacuum_command }}"
  60. async: "{{ postgres_vacuum_wait_time }}"
  61. poll: 10
  62. register: matrix_postgres_synapse_vacuum_result
  63. # Intentionally show the results
  64. - debug: var="matrix_postgres_synapse_vacuum_result"
  65. - name: Ensure matrix-synapse is started, if it previously was
  66. service:
  67. name: matrix-synapse
  68. state: started
  69. daemon_reload: yes
  70. when: "matrix_postgres_synapse_was_running|bool"