Reorganize some files
This commit is contained in:
65
roles/matrix-server/tasks/import/import_media_store.yml
Normal file
65
roles/matrix-server/tasks/import/import_media_store.yml
Normal file
@ -0,0 +1,65 @@
|
||||
---
|
||||
|
||||
- name: Fail if playbook called incorrectly
|
||||
fail: msg="The `local_path_media_store` variable needs to be provided to this playbook, via --extra-vars"
|
||||
when: "local_path_media_store is not defined or local_path_media_store.startswith('<')"
|
||||
|
||||
- name: Check if the provided media store directory exists
|
||||
stat: path="{{ local_path_media_store }}"
|
||||
delegate_to: 127.0.0.1
|
||||
become: false
|
||||
register: local_path_media_store_stat
|
||||
|
||||
- name: Fail if provided media store directory doesn't exist on the local machine
|
||||
fail: msg="{{ local_path_media_store }} cannot be found on the local machine"
|
||||
when: "not local_path_media_store_stat.stat.exists or not local_path_media_store_stat.stat.isdir"
|
||||
|
||||
- name: Check if media store contains local_content
|
||||
stat: path="{{ local_path_media_store }}/local_content"
|
||||
delegate_to: 127.0.0.1
|
||||
become: false
|
||||
register: local_path_media_store_local_content_stat
|
||||
|
||||
- name: Check if media store contains remote_content
|
||||
stat: path="{{ local_path_media_store }}/remote_content"
|
||||
delegate_to: 127.0.0.1
|
||||
become: false
|
||||
register: local_path_media_store_remote_content_stat
|
||||
|
||||
- name: Fail if media store directory doesn't look okay (lacking remote and local content)
|
||||
fail: msg="{{ local_path_media_store }} contains neither local_content nor remote_content. It's most likely a mistake and is not a media store directory."
|
||||
when: "not local_path_media_store_local_content_stat.stat.exists and not local_path_media_store_remote_content_stat.stat.exists"
|
||||
|
||||
- name: Ensure matrix-synapse is stopped
|
||||
service: name=matrix-synapse state=stopped daemon_reload=yes
|
||||
register: stopping_result
|
||||
|
||||
- name: Ensure provided media store directory is copied to the server
|
||||
synchronize:
|
||||
src: "{{ local_path_media_store }}/"
|
||||
dest: "{{ matrix_synapse_media_store_path }}"
|
||||
delete: yes
|
||||
# It's wasteful to preserve owner/group now. We chown below anyway.
|
||||
owner: no
|
||||
group: no
|
||||
times: "{{ False if matrix_s3_media_store_enabled else True }}"
|
||||
perms: "{{ False if matrix_s3_media_store_enabled else True }}"
|
||||
|
||||
# This is for the generic case and fails in other cases (remote file systems),
|
||||
# because in such cases the base path (matrix_synapse_media_store_path) is a mount point.
|
||||
- name: Ensure media store permissions are correct (generic case)
|
||||
file:
|
||||
path: "{{ matrix_synapse_media_store_path }}"
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_username }}"
|
||||
recurse: yes
|
||||
when: "not matrix_s3_media_store_enabled"
|
||||
|
||||
# We don't chown for Goofys, because due to the way it's mounted,
|
||||
# all files become owned by whoever needs to own them.
|
||||
|
||||
- name: Ensure Matrix Synapse is started (if it previously was)
|
||||
service: name="{{ item }}" state=started daemon_reload=yes
|
||||
when: stopping_result.changed
|
||||
with_items:
|
||||
- matrix-synapse
|
53
roles/matrix-server/tasks/import/import_postgres.yml
Normal file
53
roles/matrix-server/tasks/import/import_postgres.yml
Normal file
@ -0,0 +1,53 @@
|
||||
---
|
||||
|
||||
# Pre-checks
|
||||
|
||||
- name: Fail if playbook called incorrectly
|
||||
fail: msg="The `server_path_postgres_dump` variable needs to be provided to this playbook, via --extra-vars"
|
||||
when: "server_path_postgres_dump is not defined or server_path_postgres_dump.startswith('<')"
|
||||
|
||||
- name: Check if the provided Postgres dump file exists
|
||||
stat: path="{{ server_path_postgres_dump }}"
|
||||
register: result_server_path_postgres_dump_stat
|
||||
|
||||
- name: Fail if provided Postgres dump file doesn't exists
|
||||
fail: msg="File cannot be found on the local machine at {{ server_path_postgres_dump }}"
|
||||
when: not result_server_path_postgres_dump_stat.stat.exists
|
||||
|
||||
- include: tasks/util/detect_existing_postgres_version.yml
|
||||
|
||||
- name: Abort, if no existing Postgres version detected
|
||||
fail: msg="Could not find existing Postgres installation"
|
||||
when: "not matrix_postgres_detected_existing"
|
||||
|
||||
|
||||
# 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 started
|
||||
service: name=matrix-postgres state=started 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
|
||||
|
||||
- name: Perform Postgres database import
|
||||
command: |
|
||||
/usr/bin/docker run --rm --name matrix-postgres-import \
|
||||
--network={{ matrix_docker_network }} \
|
||||
--env-file={{ matrix_environment_variables_data_path }}/env-postgres-pgsql-docker \
|
||||
-v {{ server_path_postgres_dump }}:{{ server_path_postgres_dump }}:ro \
|
||||
--entrypoint=/bin/sh
|
||||
{{ matrix_postgres_docker_image_latest }}
|
||||
-c 'cat {{ server_path_postgres_dump }} | \
|
||||
{{ 'gunzip |' if server_path_postgres_dump.endswith('.gz') else '' }}
|
||||
psql -v ON_ERROR_STOP=1 -h matrix-postgres'
|
79
roles/matrix-server/tasks/import/import_sqlite_db.yml
Normal file
79
roles/matrix-server/tasks/import/import_sqlite_db.yml
Normal file
@ -0,0 +1,79 @@
|
||||
---
|
||||
|
||||
- name: Fail if playbook called incorrectly
|
||||
fail: msg="The `local_path_homeserver_db` variable needs to be provided to this playbook, via --extra-vars"
|
||||
when: "local_path_homeserver_db is not defined or local_path_homeserver_db.startswith('<')"
|
||||
|
||||
- name: Check if the provided SQLite homeserver.db file exists
|
||||
stat: path="{{ local_path_homeserver_db }}"
|
||||
delegate_to: 127.0.0.1
|
||||
become: false
|
||||
register: local_path_homeserver_db_stat
|
||||
|
||||
- name: Fail if provided SQLite homeserver.db file doesn't exist
|
||||
fail: msg="File cannot be found on the local machine at {{ local_path_homeserver_db }}"
|
||||
when: not local_path_homeserver_db_stat.stat.exists
|
||||
|
||||
- name: Ensure scratchpad directory exists
|
||||
file:
|
||||
path: "{{ matrix_scratchpad_dir }}"
|
||||
state: directory
|
||||
mode: 0755
|
||||
owner: "{{ matrix_user_username }}"
|
||||
group: "{{ matrix_user_username }}"
|
||||
|
||||
- name: Ensure provided SQLite homeserver.db file is copied to scratchpad directory on the server
|
||||
synchronize:
|
||||
src: "{{ local_path_homeserver_db }}"
|
||||
dest: "{{ matrix_scratchpad_dir }}/homeserver.db"
|
||||
|
||||
- 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 while, so that Postgres can manage to start
|
||||
pause: seconds=7
|
||||
|
||||
# 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 /scratchpad/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"
|
||||
- "{{ matrix_scratchpad_dir }}:/scratchpad"
|
||||
networks:
|
||||
- name: "{{ matrix_docker_network }}"
|
||||
|
||||
- name: Ensure scratchpad directory is deleted
|
||||
file:
|
||||
path: "{{ matrix_scratchpad_dir }}"
|
||||
state: absent
|
Reference in New Issue
Block a user