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

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