From e4e99d2a2f6a594ed83e45c97634e4f7b9aecfec Mon Sep 17 00:00:00 2001 From: Fabio Scotto di Santolo Date: Tue, 3 Nov 2026 23:57:06 +0100 Subject: [PATCH] Fix ai-media automount --- .../desktop_ai_media/files/check_storage.py | 2 +- ansible/roles/desktop_ai_media/tasks/main.yml | 35 +++++++++++++++++-- .../ai-media-bind-restarter.service.j2 | 7 ++++ .../templates/ai-media-bind.automount.j2 | 1 + 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 ansible/roles/desktop_ai_media/templates/ai-media-bind-restarter.service.j2 diff --git a/ansible/roles/desktop_ai_media/files/check_storage.py b/ansible/roles/desktop_ai_media/files/check_storage.py index 1e008d6..995fd1a 100644 --- a/ansible/roles/desktop_ai_media/files/check_storage.py +++ b/ansible/roles/desktop_ai_media/files/check_storage.py @@ -20,7 +20,7 @@ backing_mount_at_root = any( p == root and kind != "autofs" for p, kind in mounts ) if automount_at_root and not backing_mount_at_root: - raise SystemExit("Media storage automount is not active; refusing to start") + raise SystemExit("Media storage is not mounted; refusing to start") covering = [ (p, kind) for p, kind in mounts if kind != "autofs" and (root == p or root.is_relative_to(p)) diff --git a/ansible/roles/desktop_ai_media/tasks/main.yml b/ansible/roles/desktop_ai_media/tasks/main.yml index 416bd4f..32a45e6 100644 --- a/ansible/roles/desktop_ai_media/tasks/main.yml +++ b/ansible/roles/desktop_ai_media/tasks/main.yml @@ -72,9 +72,26 @@ mode: "0644" notify: Reload systemd units + - name: Install ai-media bind automount failure restarter + ansible.builtin.template: + src: ai-media-bind-restarter.service.j2 + dest: /etc/systemd/system/ai-media-bind-restarter.service + owner: root + group: root + mode: "0644" + notify: Reload systemd units + - name: Flush systemd unit changes ansible.builtin.meta: flush_handlers + - name: Stop a stale ai-media bind mount when the Backup source is absent + ansible.builtin.systemd_service: + name: "{{ desktop_ai_media_bind_mount_unit.stdout }}" + state: stopped + when: + - desktop_ai_media_root in (ansible_facts['mounts'] | default([]) | selectattr('fstype', 'ne', 'autofs') | map(attribute='mount') | list) + - desktop_ai_media_external_mountpoint not in (ansible_facts['mounts'] | default([]) | map(attribute='mount') | list) + - name: Enable and start ai-media bind automount ansible.builtin.systemd_service: name: "{{ desktop_ai_media_bind_automount_unit.stdout }}" @@ -84,6 +101,13 @@ - name: Configure isolated desktop media tools as the desktop user become: false block: + - name: Determine whether the ai-media storage source is currently available + ansible.builtin.set_fact: + desktop_ai_media_external_available: >- + {{ (not (desktop_ai_media_external_storage_enabled | bool)) or + (desktop_ai_media_external_mountpoint in + (ansible_facts['mounts'] | default([]) | map(attribute='mount') | list)) }} + - name: Load pinned public model manifest ansible.builtin.include_vars: models.yml @@ -131,8 +155,15 @@ stdin: "{{ lookup('ansible.builtin.file', role_path + '/files/check_storage.py') }}" changed_when: false check_mode: false + when: desktop_ai_media_external_available | bool - - name: Create private application and media directories + - name: Create the data-free local build context + ansible.builtin.file: + path: "{{ desktop_ai_media_build_root }}" + state: directory + mode: "0700" + + - name: Create private application and media directories on mounted media storage ansible.builtin.file: path: "{{ item }}" state: directory @@ -148,7 +179,7 @@ - "{{ desktop_ai_media_root }}/state" - "{{ desktop_ai_media_root }}/state/facefusion" - "{{ desktop_ai_media_root }}/state/rvc" - - "{{ desktop_ai_media_build_root }}" + when: desktop_ai_media_external_available | bool - name: Ensure user launcher directories exist without changing existing permissions ansible.builtin.file: diff --git a/ansible/roles/desktop_ai_media/templates/ai-media-bind-restarter.service.j2 b/ansible/roles/desktop_ai_media/templates/ai-media-bind-restarter.service.j2 new file mode 100644 index 0000000..1295a5e --- /dev/null +++ b/ansible/roles/desktop_ai_media/templates/ai-media-bind-restarter.service.j2 @@ -0,0 +1,7 @@ +[Unit] +Description=Recover the ai-media bind automount after an unavailable Backup volume + +[Service] +Type=oneshot +ExecStartPre=/usr/bin/sleep 3 +ExecStart=/usr/bin/bash -c '/usr/bin/systemctl restart "$(/usr/bin/systemd-escape -p --suffix=automount {{ desktop_ai_media_root }})"' diff --git a/ansible/roles/desktop_ai_media/templates/ai-media-bind.automount.j2 b/ansible/roles/desktop_ai_media/templates/ai-media-bind.automount.j2 index bc1d862..b690091 100644 --- a/ansible/roles/desktop_ai_media/templates/ai-media-bind.automount.j2 +++ b/ansible/roles/desktop_ai_media/templates/ai-media-bind.automount.j2 @@ -1,6 +1,7 @@ [Unit] Description=On-demand ai-media bind mount from the Backup LUKS volume ConditionPathIsDirectory={{ desktop_ai_media_root }} +OnFailure=ai-media-bind-restarter.service [Automount] Where={{ desktop_ai_media_root }}