2019-01-12 16:53:00 +01:00
|
|
|
---
|
|
|
|
|
2021-01-14 22:23:46 +01:00
|
|
|
- name: Determine whether we should make services autostart
|
2020-11-30 19:58:21 +01:00
|
|
|
set_fact:
|
|
|
|
matrix_services_autostart_enabled_bool: "{{ true if matrix_services_autostart_enabled|default('') == '' else matrix_services_autostart_enabled|bool }}"
|
|
|
|
|
2020-07-29 12:37:05 +02:00
|
|
|
- name: Ensure systemd is reloaded
|
2019-01-12 16:53:00 +01:00
|
|
|
service:
|
|
|
|
daemon_reload: yes
|
|
|
|
|
2020-07-29 12:37:05 +02:00
|
|
|
- name: Ensure Matrix services are stopped
|
2019-01-12 16:53:00 +01:00
|
|
|
service:
|
|
|
|
name: "{{ item }}"
|
|
|
|
state: stopped
|
|
|
|
with_items: "{{ matrix_systemd_services_list }}"
|
2020-07-29 12:37:05 +02:00
|
|
|
when: not ansible_check_mode
|
2019-01-12 16:53:00 +01:00
|
|
|
|
2020-07-29 12:37:05 +02:00
|
|
|
- name: Ensure Matrix services are started
|
2019-01-12 16:53:00 +01:00
|
|
|
service:
|
|
|
|
name: "{{ item }}"
|
2020-11-30 19:58:21 +01:00
|
|
|
enabled: "{{ matrix_services_autostart_enabled_bool }}"
|
2019-01-12 16:53:00 +01:00
|
|
|
state: started
|
2019-04-03 10:19:06 +02:00
|
|
|
with_items: "{{ matrix_systemd_services_list }}"
|
2020-07-29 12:37:05 +02:00
|
|
|
when: not ansible_check_mode
|
2019-04-03 10:19:06 +02:00
|
|
|
|
|
|
|
# If we check service state immediately, we may succeed,
|
|
|
|
# because it takes some time for the service to attempt to start and actually fail.
|
|
|
|
#
|
|
|
|
# Waiting too long (30s) may not work for a similar reason,
|
|
|
|
# as we may run into systemd's automatic restart logic retrying the service.
|
|
|
|
- name: Wait a bit, so that services can start (or fail)
|
|
|
|
wait_for:
|
2021-03-16 14:52:26 +01:00
|
|
|
timeout: 15
|
2019-04-03 10:19:06 +02:00
|
|
|
delegate_to: 127.0.0.1
|
|
|
|
become: false
|
|
|
|
|
2020-03-29 14:48:46 +02:00
|
|
|
- block:
|
|
|
|
- name: Populate service facts
|
|
|
|
service_facts:
|
2019-04-03 10:19:06 +02:00
|
|
|
|
2020-03-29 14:48:46 +02:00
|
|
|
- name: Fail if service isn't detected to be running
|
|
|
|
fail:
|
|
|
|
msg: >-
|
|
|
|
{{ item }} was not detected to be running.
|
|
|
|
It's possible that there's a configuration problem or another service on your server interferes with it (uses the same ports, etc.).
|
|
|
|
Try running `systemctl status {{ item }}` and `journalctl -fu {{ item }}` on the server to investigate.
|
|
|
|
with_items: "{{ matrix_systemd_services_list }}"
|
|
|
|
when:
|
2021-01-14 22:23:46 +01:00
|
|
|
- "item.endswith('.service') and (ansible_facts.services[item]|default(none) is none or ansible_facts.services[item].state != 'running')"
|
2020-03-29 14:48:46 +02:00
|
|
|
when: " ansible_distribution != 'Archlinux'"
|
2020-03-28 17:33:35 +01:00
|
|
|
|
2020-03-29 14:48:46 +02:00
|
|
|
- block:
|
|
|
|
# Currently there is a bug in ansible that renders is incompatible with systemd.
|
|
|
|
# service_facts is not collecting the data successfully.
|
|
|
|
# Therefore iterating here manually
|
|
|
|
- name: Fetch systemd information
|
|
|
|
systemd:
|
|
|
|
name: "{{ item }}"
|
|
|
|
register: systemdstatus
|
|
|
|
with_items: "{{ matrix_systemd_services_list }}"
|
2020-03-28 17:33:35 +01:00
|
|
|
|
2020-03-29 14:48:46 +02:00
|
|
|
- name: Fail if service isn't detected to be running
|
|
|
|
fail:
|
|
|
|
msg: >-
|
|
|
|
{{ item.item }} was not detected to be running.
|
|
|
|
It's possible that there's a configuration problem or another service on your server interferes with it (uses the same ports, etc.).
|
|
|
|
Try running `systemctl status {{ item.item }}` and `journalctl -fu {{ item.item }}` on the server to investigate.
|
|
|
|
with_items: "{{ systemdstatus.results }}"
|
|
|
|
when: "item.status['ActiveState'] != 'active'"
|
|
|
|
when: "ansible_distribution == 'Archlinux'"
|