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.
 
 

49 lines
2.2 KiB

  1. ---
  2. - name: Ensure systemd is reloaded
  3. ansible.builtin.service:
  4. daemon_reload: true
  5. - name: Ensure Matrix services are stopped
  6. ansible.builtin.service:
  7. name: "{{ item.name }}"
  8. state: stopped
  9. with_items: "{{ matrix_systemd_services_list | sort (attribute='priority,name', reverse=true) }}"
  10. when: not ansible_check_mode
  11. - name: Ensure Matrix services are started
  12. ansible.builtin.service:
  13. name: "{{ item.name }}"
  14. state: started
  15. enabled: "{{ matrix_systemd_services_autostart_enabled }}"
  16. with_items: "{{ matrix_systemd_services_list | sort (attribute='priority,name') }}"
  17. when: not ansible_check_mode
  18. # If we check service state immediately, we may succeed,
  19. # because it takes some time for the service to attempt to start and actually fail.
  20. #
  21. # Waiting too long (30s) may not work for a similar reason,
  22. # as we may run into systemd's automatic restart logic retrying the service.
  23. - name: Wait a bit, so that services can start (or fail)
  24. ansible.builtin.wait_for:
  25. timeout: "{{ matrix_common_after_systemd_service_start_wait_for_timeout_seconds }}"
  26. delegate_to: 127.0.0.1
  27. become: false
  28. - block:
  29. - name: Populate service facts
  30. ansible.builtin.service_facts:
  31. - name: Fail if service isn't detected to be running
  32. ansible.builtin.fail:
  33. msg: >-
  34. {{ item }} was not detected to be running.
  35. It's possible that there's a configuration problem or another service on your server interferes with it (uses the same ports, etc.).
  36. Try running `systemctl status {{ item }}` and `journalctl -fu {{ item }}` on the server to investigate.
  37. 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.
  38. You can consider raising the value of the `matrix_common_after_systemd_service_start_wait_for_timeout_seconds` variable.
  39. See `roles/custom/matrix-common-after/defaults/main.yml` for more details about that.
  40. with_items: "{{ matrix_systemd_services_list | map(attribute='name') }}"
  41. when:
  42. - "item.endswith('.service') and (ansible_facts.services[item] | default(none) is none or ansible_facts.services[item].state != 'running')"