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

118 строки
4.0 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 synapse-janitor."
  6. when: "not matrix_postgres_enabled|bool"
  7. - name: Fail if not aware of the risks
  8. fail:
  9. msg: >-
  10. Using Synapse Janitor is considered dangerous and may break your database.
  11. See https://github.com/spantaleev/matrix-docker-ansible-deploy/issues/465.
  12. If you'd like to run it anyway, add `--extra-vars='i_know_synapse_janitor_is_dangerous=1'` to your command.
  13. when: "i_know_synapse_janitor_is_dangerous|default('') == ''"
  14. # Defaults
  15. - name: Set postgres_start_wait_time, if not provided
  16. set_fact:
  17. postgres_start_wait_time: 15
  18. when: "postgres_start_wait_time|default('') == ''"
  19. - name: Set postgres_synapse_janitor_wait_time, if not provided
  20. set_fact:
  21. postgres_synapse_janitor_wait_time: "{{ 7 * 86400 }}"
  22. when: "postgres_synapse_janitor_wait_time|default('') == ''"
  23. - name: Set postgres_synapse_janitor_tool_path, if not provided
  24. set_fact:
  25. postgres_synapse_janitor_tool_path: "{{ matrix_postgres_base_path }}/synapse_janitor.sql"
  26. when: "postgres_synapse_janitor_tool_path|default('') == ''"
  27. # Actual janitor work
  28. - name: Download synapse-janitor tool
  29. get_url:
  30. url: "{{ matrix_postgres_tool_synapse_janitor }}"
  31. dest: "{{ postgres_synapse_janitor_tool_path }}"
  32. force: true
  33. mode: 0550
  34. owner: "{{ matrix_user_username }}"
  35. group: "{{ matrix_user_groupname }}"
  36. - name: Ensure matrix-postgres is started
  37. service:
  38. name: matrix-postgres
  39. state: started
  40. daemon_reload: yes
  41. - name: Wait a bit, so that Postgres can start
  42. wait_for:
  43. timeout: "{{ postgres_start_wait_time }}"
  44. delegate_to: 127.0.0.1
  45. become: false
  46. - import_tasks: tasks/util/detect_existing_postgres_version.yml
  47. - name: Abort, if no existing Postgres version detected
  48. fail:
  49. msg: "Could not find existing Postgres installation"
  50. when: "not matrix_postgres_detected_existing|bool"
  51. - name: Generate Postgres database synapse-janitor command
  52. set_fact:
  53. matrix_postgres_synapse_janitor_command: >-
  54. {{ matrix_host_command_docker }} run --rm --name matrix-postgres-synapse-janitor
  55. --user={{ matrix_user_uid }}:{{ matrix_user_gid }}
  56. --cap-drop=ALL
  57. --network={{ matrix_docker_network }}
  58. --env-file={{ matrix_postgres_base_path }}/env-postgres-psql
  59. --mount type=bind,src={{ postgres_synapse_janitor_tool_path }},dst=/synapse_janitor.sql,ro=true
  60. {{ matrix_postgres_docker_image_latest }}
  61. psql -v ON_ERROR_STOP=1 -h matrix-postgres {{ matrix_synapse_database_database }} -f /synapse_janitor.sql
  62. - name: Note about Postgres purging alternative
  63. debug:
  64. msg: >-
  65. Running synapse-janitor with the following Postgres command: `{{ matrix_postgres_synapse_janitor_command }}`.
  66. If this crashes, you can stop all processes (`systemctl stop matrix-*`),
  67. start Postgres only (`systemctl start matrix-postgres`)
  68. and manually run the above command directly on the server.
  69. - name: Populate service facts
  70. service_facts:
  71. - set_fact:
  72. 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' }}"
  73. - name: Ensure matrix-synapse is stopped
  74. service:
  75. name: matrix-synapse
  76. state: stopped
  77. daemon_reload: yes
  78. - name: Run synapse-janitor
  79. command: "{{ matrix_postgres_synapse_janitor_command }}"
  80. async: "{{ postgres_synapse_janitor_wait_time }}"
  81. poll: 10
  82. register: matrix_postgres_synapse_janitor_result
  83. # Intentionally show the results
  84. - debug: var="matrix_postgres_synapse_janitor_result"
  85. - name: Ensure matrix-synapse is started, if it previously was
  86. service:
  87. name: matrix-synapse
  88. state: started
  89. daemon_reload: yes
  90. when: "matrix_postgres_synapse_was_running|bool"
  91. - name: Delete synapse-janitor tool
  92. file:
  93. path: "{{ postgres_synapse_janitor_tool_path }}"
  94. state: absent