51312b8250
As suggested in #63 (Github issue), splitting the playbook's logic into multiple roles will be beneficial for maintainability. This patch realizes this split. Still, some components affect others, so the roles are not really independent of one another. For example: - disabling mxisd (`matrix_mxisd_enabled: false`), causes Synapse and riot-web to reconfigure themselves with other (public) Identity servers. - enabling matrix-corporal (`matrix_corporal_enabled: true`) affects how reverse-proxying (by `matrix-nginx-proxy`) is done, in order to put matrix-corporal's gateway server in front of Synapse We may be able to move away from such dependencies in the future, at the expense of a more complicated manual configuration, but it's probably not worth sacrificing the convenience we have now. As part of this work, the way we do "start components" has been redone now to use a loop, as suggested in #65 (Github issue). This should make restarting faster and more reliable.
85 lines
2.5 KiB
YAML
85 lines
2.5 KiB
YAML
---
|
|
|
|
# Pre-checks
|
|
|
|
- name: Fail if playbook called incorrectly
|
|
fail:
|
|
msg: "The `server_path_homeserver_db` variable needs to be provided to this playbook, via --extra-vars"
|
|
when: "server_path_homeserver_db is not defined or server_path_homeserver_db.startswith('<')"
|
|
|
|
- name: Check if the provided SQLite homeserver.db file exists
|
|
stat:
|
|
path: "{{ server_path_homeserver_db }}"
|
|
register: result_server_path_homeserver_db_stat
|
|
|
|
- name: Fail if provided SQLite homeserver.db file doesn't exist
|
|
fail:
|
|
msg: "File cannot be found on the server at {{ server_path_homeserver_db }}"
|
|
when: not result_server_path_homeserver_db_stat.stat.exists
|
|
|
|
|
|
# Defaults
|
|
|
|
- name: Set postgres_start_wait_time, if not provided
|
|
set_fact:
|
|
postgres_start_wait_time: 15
|
|
when: "postgres_start_wait_time|default('') == ''"
|
|
|
|
|
|
# Actual import work
|
|
|
|
- name: Ensure matrix-postgres is stopped
|
|
service:
|
|
name: matrix-postgres
|
|
state: stopped
|
|
daemon_reload: yes
|
|
|
|
- name: Ensure postgres data is wiped out
|
|
file:
|
|
path: "{{ matrix_postgres_data_path }}"
|
|
state: absent
|
|
|
|
- name: Ensure postgres data path exists
|
|
file:
|
|
path: "{{ matrix_postgres_data_path }}"
|
|
state: directory
|
|
mode: 0700
|
|
owner: "{{ matrix_user_username }}"
|
|
group: "{{ matrix_user_username }}"
|
|
|
|
- name: Ensure matrix-postgres is started
|
|
service:
|
|
name: matrix-postgres
|
|
state: restarted
|
|
daemon_reload: yes
|
|
|
|
- name: Wait a bit, so that Postgres can start
|
|
wait_for:
|
|
timeout: "{{ postgres_start_wait_time }}"
|
|
delegate_to: 127.0.0.1
|
|
become: false
|
|
|
|
# If the actual migration command (below) fails, it will leave a container behind.
|
|
# Starting it again later will relaunch that one, which may or may not work.
|
|
# To ensure we're starting from a clean state, ensure any such leftovers are removed.
|
|
- name: Cleanup any old leftover migration container
|
|
docker_container:
|
|
name: matrix-synapse-migrate
|
|
state: absent
|
|
|
|
- name: Importing SQLite database into Postgres
|
|
docker_container:
|
|
name: matrix-synapse-migrate
|
|
image: "{{ matrix_synapse_docker_image }}"
|
|
detach: no
|
|
cleanup: yes
|
|
entrypoint: /usr/local/bin/python
|
|
command: "/usr/local/bin/synapse_port_db --sqlite-database {{ server_path_homeserver_db }} --postgres-config /data/homeserver.yaml"
|
|
user: "{{ matrix_user_uid }}:{{ matrix_user_gid }}"
|
|
volumes:
|
|
- "{{ matrix_synapse_config_dir_path }}:/data"
|
|
- "{{ matrix_synapse_run_path }}:/matrix-run"
|
|
- "{{ server_path_homeserver_db }}:/{{ server_path_homeserver_db }}:ro"
|
|
networks:
|
|
- name: "{{ matrix_docker_network }}"
|