From 085a32d26f42e9c96fa5ffa3092b5f99d1ad55a6 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Mon, 10 Apr 2023 15:35:42 +0200 Subject: [PATCH] Ensure service is restarted on unit file changes At the moment we don't restart services if systemd unit file is changed. We knowingly prevent systemd_service role handlers to execute by providing `state: started` as otherwise service will be restarted twice. With that now we ensure that role handlers will also listen for systemd unit changes. Change-Id: I802ebfbdec5140b2414086c04ae1297868ec256b --- handlers/main.yml | 1 + tasks/uwsgi_post_install.yml | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index eab47b1..776da06 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -27,3 +27,4 @@ listen: - "Restart uwsgi services" - "venv changed" + - "systemd service changed" diff --git a/tasks/uwsgi_post_install.yml b/tasks/uwsgi_post_install.yml index 26377cf..85f8a49 100644 --- a/tasks/uwsgi_post_install.yml +++ b/tasks/uwsgi_post_install.yml @@ -44,8 +44,8 @@ systemd_TasksAccounting: true systemd_services: - service_name: "{{ service_var.value.service_name | default(service_var.key) }}" - enabled: yes - state: started + enabled: "{{ service_var.value.enabled | default(True) }}" + state: "{{ service_var.value.state | default('started') }}" execstarts: "{{ uwsgi_bin }}/uwsgi --autoload --ini /etc/uwsgi/{{ service_var.key }}.ini {{ (service_var.value.uwsgi_pyargv is defined) | ternary('--pyargv \"' ~ service_var.value.uwsgi_pyargv | default('') ~ '\"', '') }}" execreloads: "{{ uwsgi_bin }}/uwsgi --reload {{ uwsgi_run_dir }}/{{ service_var.key }}/{{ uwsgi_system_slice_name }}/{{ service_var.key }}.pid" config_overrides: "{{ service_var.value.init_config_overrides | default({}) | combine(uwsgi_init_config_overrides, recursive=True) }}"