2017-07-31 22:07:30 +02:00
|
|
|
---
|
|
|
|
|
2019-01-01 15:16:13 +02:00
|
|
|
# Pre-checks
|
|
|
|
|
2019-01-16 18:05:48 +02:00
|
|
|
- name: Fail if Postgres not enabled
|
|
|
|
fail:
|
|
|
|
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import."
|
|
|
|
when: "not matrix_postgres_enabled"
|
|
|
|
|
2017-07-31 22:07:30 +02:00
|
|
|
- name: Fail if playbook called incorrectly
|
2019-01-08 00:35:35 +02:00
|
|
|
fail:
|
|
|
|
msg: "The `server_path_homeserver_db` variable needs to be provided to this playbook, via --extra-vars"
|
2019-01-01 15:16:13 +02:00
|
|
|
when: "server_path_homeserver_db is not defined or server_path_homeserver_db.startswith('<')"
|
2017-07-31 22:07:30 +02:00
|
|
|
|
|
|
|
- name: Check if the provided SQLite homeserver.db file exists
|
2019-01-08 00:35:35 +02:00
|
|
|
stat:
|
|
|
|
path: "{{ server_path_homeserver_db }}"
|
2019-01-01 15:16:13 +02:00
|
|
|
register: result_server_path_homeserver_db_stat
|
2017-07-31 22:07:30 +02:00
|
|
|
|
|
|
|
- name: Fail if provided SQLite homeserver.db file doesn't exist
|
2019-01-08 00:35:35 +02:00
|
|
|
fail:
|
|
|
|
msg: "File cannot be found on the server at {{ server_path_homeserver_db }}"
|
2019-01-01 15:16:13 +02:00
|
|
|
when: not result_server_path_homeserver_db_stat.stat.exists
|
2017-07-31 22:07:30 +02:00
|
|
|
|
|
|
|
|
2019-01-01 15:16:13 +02:00
|
|
|
# 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
|
2017-07-31 22:07:30 +02:00
|
|
|
|
|
|
|
- name: Ensure matrix-postgres is stopped
|
2019-01-08 00:35:35 +02:00
|
|
|
service:
|
|
|
|
name: matrix-postgres
|
|
|
|
state: stopped
|
|
|
|
daemon_reload: yes
|
2017-07-31 22:07:30 +02:00
|
|
|
|
|
|
|
- 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
|
2019-01-08 00:35:35 +02:00
|
|
|
service:
|
|
|
|
name: matrix-postgres
|
|
|
|
state: restarted
|
|
|
|
daemon_reload: yes
|
2017-07-31 22:07:30 +02:00
|
|
|
|
2019-01-01 15:16:13 +02:00
|
|
|
- name: Wait a bit, so that Postgres can start
|
|
|
|
wait_for:
|
|
|
|
timeout: "{{ postgres_start_wait_time }}"
|
|
|
|
delegate_to: 127.0.0.1
|
|
|
|
become: false
|
2017-07-31 22:07:30 +02:00
|
|
|
|
2018-12-13 07:40:30 +02:00
|
|
|
# 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
|
|
|
|
|
2017-07-31 22:07:30 +02:00
|
|
|
- name: Importing SQLite database into Postgres
|
|
|
|
docker_container:
|
|
|
|
name: matrix-synapse-migrate
|
2018-11-01 08:46:47 +02:00
|
|
|
image: "{{ matrix_synapse_docker_image }}"
|
2017-07-31 22:07:30 +02:00
|
|
|
detach: no
|
|
|
|
cleanup: yes
|
2018-12-13 07:40:30 +02:00
|
|
|
entrypoint: /usr/local/bin/python
|
2019-01-28 11:43:32 +02:00
|
|
|
command: "/usr/local/bin/synapse_port_db --sqlite-database /{{ server_path_homeserver_db|basename }} --postgres-config /data/homeserver.yaml"
|
2017-07-31 22:07:30 +02:00
|
|
|
user: "{{ matrix_user_uid }}:{{ matrix_user_gid }}"
|
2019-01-28 11:43:32 +02:00
|
|
|
cap_drop: ['all']
|
2017-07-31 22:07:30 +02:00
|
|
|
volumes:
|
2017-09-07 11:12:31 +02:00
|
|
|
- "{{ matrix_synapse_config_dir_path }}:/data"
|
|
|
|
- "{{ matrix_synapse_run_path }}:/matrix-run"
|
2019-01-28 11:43:32 +02:00
|
|
|
- "{{ server_path_homeserver_db }}:/{{ server_path_homeserver_db|basename }}:ro"
|
2018-12-13 07:40:30 +02:00
|
|
|
networks:
|
|
|
|
- name: "{{ matrix_docker_network }}"
|