From 74845395e3b8ce2b2c8c0e641e0e4f288609df89 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Mon, 3 Apr 2023 10:19:13 +0300 Subject: [PATCH] Improve Redis support by mounting read-write redis-session.ini into the container Related to https://github.com/nextcloud/docker/issues/763 Fixes https://github.com/mother-of-all-self-hosting/ansible-role-nextcloud/issues/4 --- defaults/main.yml | 1 + tasks/install.yml | 23 +++++++++++++++++------ templates/systemd/server.service.j2 | 10 ++++++++++ vars/main.yml | 2 ++ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 73f71c6..ddac1d3 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -24,6 +24,7 @@ nextcloud_systemd_required_services_list_custom: [] nextcloud_base_path: "{{ nextcloud_base_path }}/nextcloud" nextcloud_config_path: "{{ nextcloud_base_path }}/config" nextcloud_data_path: "{{ nextcloud_base_path }}/data" +nextcloud_redis_session_ini_path: "{{ nextcloud_base_path }}/redis-session.ini" nextcloud_customized_container_src_path: "{{ nextcloud_base_path }}/customized-container-src" # SVG support for imagick can be setup like this: diff --git a/tasks/install.yml b/tasks/install.yml index 166781b..57e0c46 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -1,17 +1,28 @@ --- -- name: Ensure Nextcloud path exists +- name: Ensure Nextcloud paths exists ansible.builtin.file: path: "{{ item.path }}" - state: directory + state: "{{ item.state }}" mode: 0700 owner: "{{ nextcloud_uid }}" group: "{{ nextcloud_gid }}" with_items: - - {path: "{{ nextcloud_base_path }}", when: true} - - {path: "{{ nextcloud_config_path }}", when: true} - - {path: "{{ nextcloud_data_path }}", when: true} - - {path: "{{ nextcloud_customized_container_src_path }}", when: "{{ nextcloud_container_image_customizations_enabled }}"} + - path: "{{ nextcloud_base_path }}" + state: directory + when: true + - path: "{{ nextcloud_config_path }}" + state: directory + when: true + - path: "{{ nextcloud_data_path }}" + state: directory + when: true + - path: "{{ nextcloud_customized_container_src_path }}" + state: directory + when: "{{ nextcloud_container_image_customizations_enabled }}" + - path: "{{ nextcloud_redis_session_ini_path }}" + state: "{{ 'touch' if nextcloud_redis_is_configured else 'absent' }}" + when: true when: item.when | bool - name: Ensure Nextcloud support files installed diff --git a/templates/systemd/server.service.j2 b/templates/systemd/server.service.j2 index 8c58f6c..813c272 100644 --- a/templates/systemd/server.service.j2 +++ b/templates/systemd/server.service.j2 @@ -12,6 +12,13 @@ Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}" ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} kill {{ nextcloud_identifier }}-server 2>/dev/null || true' ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm {{ nextcloud_identifier }}-server 2>/dev/null || true' +{# + `redis-session.ini` is mounted from the host, because the container's entrypoint tries to modify `/usr/local/etc/php/conf.d/redis-session.ini` + during startup when Redis is enabled and it can't do it on a `--read-only` filesystem. + See: + - https://github.com/nextcloud/docker/issues/763 + - https://github.com/nextcloud/docker/blob/289f0bb8a3f1bd24d1633bbd01798c5476368827/26/apache/entrypoint.sh#L75-L100 +#} ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --rm \ --name={{ nextcloud_identifier }}-server \ @@ -21,6 +28,9 @@ ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ --cap-drop=ALL \ --read-only \ --mount type=bind,src={{ nextcloud_data_path }},dst=/var/www/html \ + {% if nextcloud_redis_is_configured %} + --mount type=bind,src={{ nextcloud_redis_session_ini_path }},dst=/usr/local/etc/php/conf.d/redis-session.ini \ + {% endif %} {% for mount in nextcloud_container_additional_mounts %} --mount {{ mount }} \ {% endfor %} diff --git a/vars/main.yml b/vars/main.yml index 05f280c..da5db30 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1 +1,3 @@ nextcloud_url: "{{ nextcloud_scheme }}://{{ nextcloud_hostname }}{{ nextcloud_path_prefix }}" + +nextcloud_redis_is_configured: "{{ nextcloud_redis_hostname != '' }}"