From 27a2b126bcc1cf4e647fb9c8eb637b4f4ad3b4a6 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Sun, 22 Mar 2026 10:19:45 +0200 Subject: [PATCH] Add conditional restart support to matrix-goofys Register image pull, env, and systemd service results, compute matrix_goofys_restart_necessary, and wire it into group_vars/matrix_servers instead of hardcoding restart_necessary: true. Co-Authored-By: Claude Opus 4.6 (1M context) --- group_vars/matrix_servers | 2 +- roles/custom/matrix-synapse/defaults/main.yml | 10 ++++++++++ .../matrix-synapse/tasks/goofys/setup_install.yml | 15 +++++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 627863740..b76b38fff 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -843,7 +843,7 @@ devture_systemd_service_manager_services_list_auto: | ([{ 'name': 'matrix-goofys.service', 'priority': 800, - 'restart_necessary': true, + 'restart_necessary': (matrix_goofys_restart_necessary | bool), 'groups': ['matrix', 'goofys'], }] if (matrix_synapse_enabled and matrix_s3_media_store_enabled) else []) + diff --git a/roles/custom/matrix-synapse/defaults/main.yml b/roles/custom/matrix-synapse/defaults/main.yml index 6604efea0..4bdf7571d 100644 --- a/roles/custom/matrix-synapse/defaults/main.yml +++ b/roles/custom/matrix-synapse/defaults/main.yml @@ -1648,6 +1648,16 @@ matrix_s3_media_store_aws_secret_key: "your-aws-secret-key" matrix_s3_media_store_region: "eu-central-1" matrix_s3_media_store_path: "{{ matrix_synapse_media_store_path }}" +# matrix_goofys_restart_necessary controls whether the Goofys service +# will be restarted (when true) or merely started (when false) by the +# systemd service manager role (when conditional restart is enabled). +# +# This value is automatically computed during installation based on whether +# any configuration files, the systemd service file, or the container image changed. +# The default of `false` means "no restart needed" — appropriate when the role's +# installation tasks haven't run (e.g., due to --tags skipping them). +matrix_goofys_restart_necessary: false + # Controls whether the self-check feature should validate SSL certificates. matrix_synapse_self_check_validate_certificates: true diff --git a/roles/custom/matrix-synapse/tasks/goofys/setup_install.yml b/roles/custom/matrix-synapse/tasks/goofys/setup_install.yml index 9048e430b..40a5b9602 100644 --- a/roles/custom/matrix-synapse/tasks/goofys/setup_install.yml +++ b/roles/custom/matrix-synapse/tasks/goofys/setup_install.yml @@ -20,10 +20,10 @@ source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_s3_goofys_container_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}" force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_s3_goofys_container_image_force_pull }}" - register: result + register: matrix_goofys_container_image_pull_result retries: "{{ devture_playbook_help_container_retries_count }}" delay: "{{ devture_playbook_help_container_retries_delay }}" - until: result is not failed + until: matrix_goofys_container_image_pull_result is not failed # This will throw a Permission Denied error if already mounted - name: Check Matrix Goofys external storage mountpoint path @@ -47,9 +47,20 @@ dest: "{{ matrix_synapse_config_dir_path }}/env-goofys" owner: root mode: '0600' + register: matrix_goofys_env_result - name: Ensure matrix-goofys.service installed ansible.builtin.template: src: "{{ role_path }}/templates/goofys/systemd/matrix-goofys.service.j2" dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-goofys.service" mode: '0644' + register: matrix_goofys_systemd_service_result + +- name: Determine whether Goofys needs a restart + ansible.builtin.set_fact: + matrix_goofys_restart_necessary: >- + {{ + matrix_goofys_env_result.changed | default(false) + or matrix_goofys_systemd_service_result.changed | default(false) + or matrix_goofys_container_image_pull_result.changed | default(false) + }}