You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.8 KiB
87 lines
2.8 KiB
7 years ago
|
---
|
||
|
|
||
6 years ago
|
# Pre-checks
|
||
|
|
||
6 years ago
|
- name: Fail if Postgres not enabled
|
||
|
fail:
|
||
|
msg: "Postgres via the matrix-postgres role is not enabled (`matrix_postgres_enabled`). Cannot import."
|
||
6 years ago
|
when: "not matrix_postgres_enabled|bool"
|
||
6 years ago
|
|
||
7 years ago
|
- name: Fail if playbook called incorrectly
|
||
6 years ago
|
fail:
|
||
|
msg: "The `server_path_homeserver_db` variable needs to be provided to this playbook, via --extra-vars"
|
||
6 years ago
|
when: "server_path_homeserver_db is not defined or server_path_homeserver_db.startswith('<')"
|
||
7 years ago
|
|
||
|
- name: Check if the provided SQLite homeserver.db file exists
|
||
6 years ago
|
stat:
|
||
|
path: "{{ server_path_homeserver_db }}"
|
||
6 years ago
|
register: result_server_path_homeserver_db_stat
|
||
7 years ago
|
|
||
|
- name: Fail if provided SQLite homeserver.db file doesn't exist
|
||
6 years ago
|
fail:
|
||
|
msg: "File cannot be found on the server at {{ server_path_homeserver_db }}"
|
||
6 years ago
|
when: "not result_server_path_homeserver_db_stat.stat.exists"
|
||
7 years ago
|
|
||
|
|
||
6 years ago
|
# 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
|
||
7 years ago
|
|
||
|
- name: Ensure matrix-postgres is stopped
|
||
6 years ago
|
service:
|
||
|
name: matrix-postgres
|
||
|
state: stopped
|
||
|
daemon_reload: yes
|
||
7 years ago
|
|
||
|
- 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 }}"
|
||
5 years ago
|
group: "{{ matrix_user_groupname }}"
|
||
7 years ago
|
|
||
|
- name: Ensure matrix-postgres is started
|
||
6 years ago
|
service:
|
||
|
name: matrix-postgres
|
||
|
state: restarted
|
||
|
daemon_reload: yes
|
||
7 years ago
|
|
||
6 years ago
|
- name: Wait a bit, so that Postgres can start
|
||
|
wait_for:
|
||
|
timeout: "{{ postgres_start_wait_time }}"
|
||
|
delegate_to: 127.0.0.1
|
||
|
become: false
|
||
7 years ago
|
|
||
6 years ago
|
# We don't use the `docker_container` module, because using it with `cap_drop` requires
|
||
|
# a very recent version, which is not available for a lot of people yet.
|
||
|
#
|
||
|
# Also, some old `docker_container` versions were buggy and would leave containers behind
|
||
|
# on failure, which we had to work around to allow retries (by re-running the playbook).
|
||
|
- name: Import SQLite database into Postgres
|
||
|
command: |
|
||
|
docker run
|
||
|
--rm
|
||
|
--name=matrix-synapse-migrate
|
||
4 years ago
|
--log-driver=none
|
||
6 years ago
|
--user={{ matrix_user_uid }}:{{ matrix_user_gid }}
|
||
|
--cap-drop=ALL
|
||
|
--network={{ matrix_docker_network }}
|
||
|
--entrypoint=python
|
||
4 years ago
|
--mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/data
|
||
|
--mount type=bind,src={{ matrix_synapse_config_dir_path }},dst=/matrix-media-store-parent/media-store
|
||
|
--mount type=bind,src={{ server_path_homeserver_db }},dst=/{{ server_path_homeserver_db|basename }}
|
||
6 years ago
|
{{ matrix_synapse_docker_image }}
|
||
|
/usr/local/bin/synapse_port_db --sqlite-database /{{ server_path_homeserver_db|basename }} --postgres-config /data/homeserver.yaml
|