Matrix Docker Ansible eploy
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.
 
 

85 lines
4.2 KiB

  1. {#
  2. SPDX-FileCopyrightText: 2024 MDAD Team and contributors
  3. SPDX-License-Identifier: AGPL-3.0-or-later
  4. #}
  5. #jinja2: lstrip_blocks: "True"
  6. [Unit]
  7. Description=Dendrite server
  8. {% for service in matrix_dendrite_systemd_required_services_list %}
  9. Requires={{ service }}
  10. After={{ service }}
  11. {% endfor %}
  12. {% for service in matrix_dendrite_systemd_wanted_services_list %}
  13. Wants={{ service }}
  14. {% endfor %}
  15. DefaultDependencies=no
  16. [Service]
  17. Type=simple
  18. Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}"
  19. ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop --time={{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-dendrite 2>/dev/null || true'
  20. ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-dendrite 2>/dev/null || true'
  21. {% if (postgres_identifier + '.service') in matrix_dendrite_systemd_required_services_list %}
  22. # Dendrite is too quick to start in relation to its Postgres dependency.
  23. # Delay Dendrite startup to avoid failing with: "failed to connect to accounts db" ("pq: the database system is starting up").
  24. ExecStartPre={{ matrix_host_command_sleep }} 5
  25. {% endif %}
  26. ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \
  27. --rm \
  28. --name=matrix-dendrite \
  29. --log-driver=none \
  30. --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
  31. --cap-drop=ALL \
  32. --read-only \
  33. --tmpfs=/tmp:rw,noexec,nosuid,size={{ matrix_dendrite_tmp_directory_size_mb }}m \
  34. --network={{ matrix_dendrite_container_network }} \
  35. {% if matrix_dendrite_container_http_host_bind_address and matrix_dendrite_http_bind_port %}
  36. -p {{ matrix_dendrite_container_http_host_bind_address }}:{{ matrix_dendrite_http_bind_port }} \
  37. {% endif %}
  38. {% if matrix_dendrite_container_https_host_bind_address and matrix_dendrite_https_bind_port %}
  39. -p {{ matrix_dendrite_container_https_host_bind_address }}:{{ matrix_dendrite_https_bind_port }} \
  40. {% endif %}
  41. --mount type=bind,src={{ matrix_dendrite_config_dir_path }},dst=/data,ro \
  42. --mount type=bind,src={{ matrix_dendrite_storage_path }},dst=/matrix-media-store-parent,bind-propagation=slave \
  43. --mount type=bind,src={{ matrix_dendrite_nats_storage_path }},dst=/matrix-nats-store,bind-propagation=slave \
  44. --label-file={{ matrix_dendrite_base_path }}/labels \
  45. {% for volume in matrix_dendrite_container_additional_volumes %}
  46. --mount type={{ volume.type | default('bind' if '/' in volume.src else 'volume') }},src={{ volume.src }},dst={{ volume.dst }}{{ (',' + volume.options) if volume.options else '' }} \
  47. {% endfor %}
  48. {% for arg in matrix_dendrite_container_arguments %}
  49. {{ arg }} \
  50. {% endfor %}
  51. {{ matrix_dendrite_docker_image }} \
  52. -config /data/dendrite.yaml \
  53. {{ matrix_dendrite_process_extra_arguments|join(' ') }} \
  54. {% if matrix_dendrite_http_bind_address %}
  55. -http-bind-address {{ matrix_dendrite_http_bind_address }}
  56. {% endif %}
  57. {% if matrix_dendrite_https_bind_address %}
  58. -https-bind-address {{ matrix_dendrite_https_bind_address }}
  59. {% endif %}
  60. {% for network in matrix_dendrite_container_additional_networks %}
  61. ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} network connect {{ network }} matrix-dendrite
  62. {% endfor %}
  63. ExecStart={{ devture_systemd_docker_base_host_command_docker }} start --attach matrix-dendrite
  64. {% if matrix_dendrite_systemd_service_post_start_delay_seconds != 0 %}
  65. ExecStartPost=-{{ matrix_host_command_sleep }} {{ matrix_dendrite_systemd_service_post_start_delay_seconds }}
  66. {% endif %}
  67. ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop --time={{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-dendrite 2>/dev/null || true'
  68. ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-dendrite 2>/dev/null || true'
  69. ExecReload={{ devture_systemd_docker_base_host_command_docker }} exec matrix-dendrite /bin/sh -c 'kill -HUP 1'
  70. Restart=always
  71. RestartSec=30
  72. SyslogIdentifier=matrix-dendrite
  73. [Install]
  74. WantedBy=multi-user.target