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.
 
 

84 lines
3.4 KiB

  1. ---
  2. - name: Determine whether we should make services autostart
  3. set_fact:
  4. matrix_services_autostart_enabled_bool: "{{ true if matrix_services_autostart_enabled|default('') == '' else matrix_services_autostart_enabled|bool }}"
  5. - name: Ensure systemd is reloaded
  6. service:
  7. daemon_reload: yes
  8. - name: Ensure Matrix services are stopped
  9. service:
  10. name: matrix.target
  11. state: stopped
  12. when: not ansible_check_mode
  13. - name: Ensure Matrix services are enabled
  14. service:
  15. name: "{{ item }}"
  16. enabled: true
  17. with_items: "{{ matrix_systemd_services_list }}"
  18. when: not ansible_check_mode
  19. - name: Ensure Matrix services are started
  20. service:
  21. name: "matrix.target"
  22. enabled: "{{ matrix_services_autostart_enabled_bool }}"
  23. state: started
  24. when: not ansible_check_mode
  25. # If we check service state immediately, we may not succeed,
  26. # because it takes some time for the service to attempt to start and actually fail.
  27. #
  28. # Waiting too long (30s) may not work for a similar reason,
  29. # as we may run into systemd's automatic restart logic retrying the service.
  30. #
  31. # Obviously this is a terrible way of doing things
  32. # Ideally, we would use Podman's PIDFiles, but then we lose support for most OSes.
  33. # Alternatively, we could use systemd-docker, but it hasn't been updated since 2015 and is incompatible with Podman.
  34. - name: Wait a bit, so that services can start (or fail)
  35. wait_for:
  36. timeout: "{{ matrix_common_after_systemd_service_start_wait_for_timeout_seconds }}"
  37. delegate_to: 127.0.0.1
  38. become: false
  39. - block:
  40. - name: Populate service facts
  41. service_facts:
  42. - name: Fail if service isn't detected to be running
  43. fail:
  44. msg: >-
  45. {{ item }} was not detected to be running.
  46. It's possible that there's a configuration problem or another service on your server interferes with it (uses the same ports, etc.).
  47. Try running `systemctl status {{ item }}` and `journalctl -fu {{ item }}` on the server to investigate.
  48. If you're on a slow or overloaded server, it may be that services take a longer time to start and that this error is a false-positive.
  49. You can consider raising the value of the `matrix_common_after_systemd_service_start_wait_for_timeout_seconds` variable.
  50. See `roles/matrix-common-after/defaults/main.yml` for more details about that.
  51. with_items: "{{ matrix_systemd_services_list }}"
  52. when:
  53. - "item.endswith('.service') and (ansible_facts.services[item]|default(none) is none or ansible_facts.services[item].state != 'running')"
  54. when: " ansible_distribution != 'Archlinux'"
  55. - block:
  56. # Currently there is a bug in ansible that renders is incompatible with systemd.
  57. # service_facts is not collecting the data successfully.
  58. # Therefore iterating here manually
  59. - name: Fetch systemd information
  60. systemd:
  61. name: "{{ item }}"
  62. register: systemdstatus
  63. with_items: "{{ matrix_systemd_services_list }}"
  64. - name: Fail if service isn't detected to be running
  65. fail:
  66. msg: >-
  67. {{ item.item }} was not detected to be running.
  68. It's possible that there's a configuration problem or another service on your server interferes with it (uses the same ports, etc.).
  69. Try running `systemctl status {{ item.item }}` and `journalctl -fu {{ item.item }}` on the server to investigate.
  70. with_items: "{{ systemdstatus.results }}"
  71. when: "item.status['ActiveState'] != 'active'"
  72. when: "ansible_distribution == 'Archlinux'"