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.
 
 

55 regels
2.7 KiB

  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2026 Chiu Ki Sit
  3. #
  4. # SPDX-License-Identifier: AGPL-3.0-or-later
  5. #
  6. # Boot recovery for Matrix services on Synology DSM.
  7. #
  8. # This script runs after multi-user.target (outside Container Manager's dependency
  9. # chain) and does two things:
  10. #
  11. # 1. Makes {{ matrix_base_synology_volume_path }} mount-shared so Docker bind-propagation=slave mounts work.
  12. # Inserting this into the systemd chain Before=pkg-ContainerManager-dockerd.service
  13. # causes Container Manager to detect a broken dependency and prompt for repair,
  14. # so it must run here instead, after Docker is already up.
  15. #
  16. # 2. Starts any enabled matrix-*.service that systemd skipped at boot.
  17. # Synology's systemd drops services with multi-level dependency chains
  18. # (e.g. traefik -> socket-proxy -> docker) from the boot activation queue.
  19. # Services that need bind-propagation=slave (e.g. matrix-synapse) are
  20. # created after step 1, so the propagation is already in effect.
  21. # Wait up to 120s for Docker to be ready
  22. i=0
  23. while [ "$i" -lt 60 ]; do
  24. {{ devture_systemd_docker_base_host_command_docker }} info >/dev/null 2>&1 && break
  25. i=$((i + 1))
  26. sleep 2
  27. done
  28. if ! {{ devture_systemd_docker_base_host_command_docker }} info >/dev/null 2>&1; then
  29. echo "matrix-synology-boot-fix: Docker not ready after 120s, aborting" >&2
  30. exit 1
  31. fi
  32. # Make {{ matrix_base_synology_volume_path }} shared so Docker bind-propagation=slave mounts work correctly.
  33. # Must run after Docker is up to avoid interfering with Container Manager's
  34. # integrity checks, but before matrix-synapse (and any other service using
  35. # bind-propagation=slave) creates its containers.
  36. /bin/mount --make-shared {{ matrix_base_synology_volume_path }}
  37. echo "matrix-synology-boot-fix: {{ matrix_base_synology_volume_path }} set to shared mount propagation"
  38. # Start any enabled matrix-*.service that is inactive or failed.
  39. # Both states indicate the service did not come up at boot — either skipped by
  40. # Synology's boot ordering or failed due to Docker/mount-propagation not being
  41. # ready yet (the conditions above now satisfy those prerequisites).
  42. {{ devture_systemd_docker_base_host_command_systemctl }} list-unit-files 'matrix-*.service' --state=enabled --no-legend 2>/dev/null | \
  43. while read -r unit _state; do
  44. [ "$unit" = "matrix-synology-boot-fix.service" ] && continue
  45. status="$({{ devture_systemd_docker_base_host_command_systemctl }} is-active "$unit" 2>/dev/null)"
  46. if [ "$status" = "inactive" ] || [ "$status" = "failed" ]; then
  47. echo "matrix-synology-boot-fix: starting $unit (was $status)"
  48. {{ devture_systemd_docker_base_host_command_systemctl }} start "$unit"
  49. fi
  50. done