From 43d194d886ca02f58435c3a065f8422b5ee42a4d Mon Sep 17 00:00:00 2001 From: Sanjeev Rohila Date: Thu, 11 Jul 2024 15:32:45 +0530 Subject: [PATCH 1/7] Adding logic to take case the /export/home mount before delting /export/home DLPX-89763 DLPX-86523 delphix-platform changes PR URL: https://www.github.com/delphix/delphix-platform/pull/477 --- debian/preinst | 48 ++++++++++++++++ .../roles/delphix-platform/tasks/main.yml | 56 ++++++++++++++++++- 2 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 debian/preinst diff --git a/debian/preinst b/debian/preinst new file mode 100644 index 000000000..0278f46cf --- /dev/null +++ b/debian/preinst @@ -0,0 +1,48 @@ +#!/bin/bash -eux +# +# Copyright 2024 Delphix +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +case $1 in +upgrade) + # Checking the fstab file if the /export/home entry + # is present in the /etc/fstab, In case of container + # upgrade the file is already changed by the + # container-upgrade script and we dont need to do + # it again. + fs_tab=/etc/fstab + auto_master=/etc/auto.master + + if grep -q "\/export\/home" "$fs_tab"; then + sed -i 's|/export/home|/home|g' "$fs_tab" + mount /home + fi + + if [[ -e $auto_master ]]; then + if grep -q "\/home\s+auto_home\s+-nobrowse" "$auto_master"; then + sed -i 's|/home auto_home -nobrowse|#/home auto_home -nobrowse|g' "$auto_master" + systemctl restart autofs + fi + fi + + passwd_file=/etc/passwd + if grep -q "\/export\/home" "$passwd_file"; then + sed -i 's/\/export\/home/\/home/g' /etc/passwd + fi + + ;; +esac + +exit 0 diff --git a/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml b/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml index 36f1956af..5ae9342f8 100644 --- a/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml +++ b/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml @@ -22,7 +22,7 @@ # it below; otherwise that task will fail. # - file: - path: /export/home + path: /home state: directory mode: 0755 @@ -35,7 +35,7 @@ shell: /bin/bash create_home: yes comment: Delphix User - home: /export/home/delphix + home: /home/delphix # # In order for this locale to be used (e.g. by virtualization) we need @@ -689,7 +689,7 @@ - name: Source bash completion blockinfile: - dest: "/export/home/delphix/.bashrc" + dest: "/home/delphix/.bashrc" block: | . /etc/bash_completion.d/systemctl . /etc/bash_completion.d/zfs @@ -738,3 +738,53 @@ path: /etc/environment state: absent regexp: '^\s*PATH\s*=' + +# +# Soft link creation in case it doesn't exist +# +- name: Check export + ansible.builtin.stat: + path: /export + register: export_status + +- name: Check export home + ansible.builtin.stat: + path: /export/home + when: export_status.stat.exists and export_status.stat.isdir + register: export_home_status + +# +# Before deleting the /export/home directory if the +# home data set is mounted on /export/home if its +# mounted remove if first and then go ahead. +# +- name: Check if the path is mounted + ansible.builtin.shell: | + mount | grep /export/home + register: mount_status + ignore_errors: yes + +- name: Unmount the path if it is mounted + ansible.builtin.mount: + path: /export/home + state: unmounted + when: mount_status.rc == 0 + +- name: Delete home directory + ansible.builtin.file: + path: /export/home + state: absent + when: not export_status.stat.exists or export_home_status.stat.exists and export_home_status.stat.isdir + +- name: Create export directory + ansible.builtin.file: + path: /export + state: directory + mode: 0755 + when: not export_status.stat.exists + +- name: Create the soft link + ansible.builtin.file: + src: /home + dest: /export/home + state: link From 2b194ff1bea95867b29278a6df3f36d1cc015e90 Mon Sep 17 00:00:00 2001 From: Sanjeev Rohila Date: Wed, 9 Apr 2025 22:16:02 +0530 Subject: [PATCH 2/7] Changing as per Seb-s comment to alter the softlink logic. --- debian/preinst | 12 +++-- .../systemd/system/delphix-platform.service | 4 ++ .../roles/delphix-platform/tasks/main.yml | 50 ------------------- 3 files changed, 11 insertions(+), 55 deletions(-) diff --git a/debian/preinst b/debian/preinst index 0278f46cf..94442976a 100644 --- a/debian/preinst +++ b/debian/preinst @@ -17,11 +17,13 @@ case $1 in upgrade) - # Checking the fstab file if the /export/home entry - # is present in the /etc/fstab, In case of container - # upgrade the file is already changed by the - # container-upgrade script and we dont need to do - # it again. + # Home directories were previously mounted under /export/home, + # and this was changed to /home. This is the upgrade logic that + # updates the /etc/fstab file to reflect that change. + # Home directories will be mounted in both /export/home and /home + # until the system is rebooted to ensure that running processes + # referencing the old /export/home paths continue to function + # while also enabling new logins under /home to work. fs_tab=/etc/fstab auto_master=/etc/auto.master diff --git a/files/common/lib/systemd/system/delphix-platform.service b/files/common/lib/systemd/system/delphix-platform.service index 89a809d67..2f0373a95 100644 --- a/files/common/lib/systemd/system/delphix-platform.service +++ b/files/common/lib/systemd/system/delphix-platform.service @@ -24,6 +24,10 @@ Before=rsync.service docker.service Type=oneshot ExecStart=/var/lib/delphix-platform/ansible/apply ExecStart=/var/lib/delphix-platform/dynamic-debug + +# Create /export/home symlink to /home if it doesn't already exist +ExecStartPost=/bin/sh -c '[ -L /export/home ] || ln -s /home /export/home' + RemainAfterExit=yes # diff --git a/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml b/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml index 5ae9342f8..893708513 100644 --- a/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml +++ b/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml @@ -738,53 +738,3 @@ path: /etc/environment state: absent regexp: '^\s*PATH\s*=' - -# -# Soft link creation in case it doesn't exist -# -- name: Check export - ansible.builtin.stat: - path: /export - register: export_status - -- name: Check export home - ansible.builtin.stat: - path: /export/home - when: export_status.stat.exists and export_status.stat.isdir - register: export_home_status - -# -# Before deleting the /export/home directory if the -# home data set is mounted on /export/home if its -# mounted remove if first and then go ahead. -# -- name: Check if the path is mounted - ansible.builtin.shell: | - mount | grep /export/home - register: mount_status - ignore_errors: yes - -- name: Unmount the path if it is mounted - ansible.builtin.mount: - path: /export/home - state: unmounted - when: mount_status.rc == 0 - -- name: Delete home directory - ansible.builtin.file: - path: /export/home - state: absent - when: not export_status.stat.exists or export_home_status.stat.exists and export_home_status.stat.isdir - -- name: Create export directory - ansible.builtin.file: - path: /export - state: directory - mode: 0755 - when: not export_status.stat.exists - -- name: Create the soft link - ansible.builtin.file: - src: /home - dest: /export/home - state: link From 78c79788b6f60aa96d035512c1c37037b7086105 Mon Sep 17 00:00:00 2001 From: Sanjeev Rohila Date: Thu, 10 Apr 2025 12:27:16 +0530 Subject: [PATCH 3/7] Changing the code to previous version to validate the comments. --- .../systemd/system/delphix-platform.service | 4 -- .../roles/delphix-platform/tasks/main.yml | 50 +++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/files/common/lib/systemd/system/delphix-platform.service b/files/common/lib/systemd/system/delphix-platform.service index 2f0373a95..89a809d67 100644 --- a/files/common/lib/systemd/system/delphix-platform.service +++ b/files/common/lib/systemd/system/delphix-platform.service @@ -24,10 +24,6 @@ Before=rsync.service docker.service Type=oneshot ExecStart=/var/lib/delphix-platform/ansible/apply ExecStart=/var/lib/delphix-platform/dynamic-debug - -# Create /export/home symlink to /home if it doesn't already exist -ExecStartPost=/bin/sh -c '[ -L /export/home ] || ln -s /home /export/home' - RemainAfterExit=yes # diff --git a/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml b/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml index 893708513..5ae9342f8 100644 --- a/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml +++ b/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml @@ -738,3 +738,53 @@ path: /etc/environment state: absent regexp: '^\s*PATH\s*=' + +# +# Soft link creation in case it doesn't exist +# +- name: Check export + ansible.builtin.stat: + path: /export + register: export_status + +- name: Check export home + ansible.builtin.stat: + path: /export/home + when: export_status.stat.exists and export_status.stat.isdir + register: export_home_status + +# +# Before deleting the /export/home directory if the +# home data set is mounted on /export/home if its +# mounted remove if first and then go ahead. +# +- name: Check if the path is mounted + ansible.builtin.shell: | + mount | grep /export/home + register: mount_status + ignore_errors: yes + +- name: Unmount the path if it is mounted + ansible.builtin.mount: + path: /export/home + state: unmounted + when: mount_status.rc == 0 + +- name: Delete home directory + ansible.builtin.file: + path: /export/home + state: absent + when: not export_status.stat.exists or export_home_status.stat.exists and export_home_status.stat.isdir + +- name: Create export directory + ansible.builtin.file: + path: /export + state: directory + mode: 0755 + when: not export_status.stat.exists + +- name: Create the soft link + ansible.builtin.file: + src: /home + dest: /export/home + state: link From 5a17a795491118f8123dbc38f74bf811d545d12e Mon Sep 17 00:00:00 2001 From: Sanjeev Rohila Date: Fri, 11 Apr 2025 15:03:37 +0530 Subject: [PATCH 4/7] Removing the softlink loginc from main.yml --- debian/preinst | 14 +++--- .../systemd/system/delphix-platform.service | 20 ++++++++ .../roles/delphix-platform/tasks/main.yml | 50 ------------------- 3 files changed, 27 insertions(+), 57 deletions(-) diff --git a/debian/preinst b/debian/preinst index 94442976a..ff3d7ae21 100644 --- a/debian/preinst +++ b/debian/preinst @@ -17,13 +17,13 @@ case $1 in upgrade) - # Home directories were previously mounted under /export/home, - # and this was changed to /home. This is the upgrade logic that - # updates the /etc/fstab file to reflect that change. - # Home directories will be mounted in both /export/home and /home - # until the system is rebooted to ensure that running processes - # referencing the old /export/home paths continue to function - # while also enabling new logins under /home to work. + # Home directories were previously mounted under /export/home, + # and this was changed to /home. This is the upgrade logic that + # updates the /etc/fstab file to reflect that change. + # Home directories will be mounted in both /export/home and /home + # until the system is rebooted to ensure that running processes + # referencing the old /export/home paths continue to function + # while also enabling new logins under /home to work. fs_tab=/etc/fstab auto_master=/etc/auto.master diff --git a/files/common/lib/systemd/system/delphix-platform.service b/files/common/lib/systemd/system/delphix-platform.service index 89a809d67..4dfaa0870 100644 --- a/files/common/lib/systemd/system/delphix-platform.service +++ b/files/common/lib/systemd/system/delphix-platform.service @@ -24,6 +24,26 @@ Before=rsync.service docker.service Type=oneshot ExecStart=/var/lib/delphix-platform/ansible/apply ExecStart=/var/lib/delphix-platform/dynamic-debug + +# Create /export/home symlink to /home if it doesn't already exist +ExecStartPost=/bin/sh -c '\ + echo "Ensuring /export/home is a symlink to /home..."; \ + if mountpoint -q /export/home; then \ + echo "/export/home is a mountpoint, unmounting..."; \ + umount /export/home || { echo "Failed to unmount /export/home"; exit 1; }; \ + fi; \ + if [ -e /export/home ] && [ ! -L /export/home ]; then \ + echo "Removing existing /export/home directory..."; \ + rm -rf /export/home; \ + fi; \ + if [ ! -d /export ]; then \ + mkdir /export; \ + fi; \ + if [ -d /export ] && [ ! -L /export/home ]; then \ + echo "Creating symlink: /export/home -> /home"; \ + ln -s /home /export/home; \ + fi;' + RemainAfterExit=yes # diff --git a/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml b/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml index 5ae9342f8..893708513 100644 --- a/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml +++ b/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml @@ -738,53 +738,3 @@ path: /etc/environment state: absent regexp: '^\s*PATH\s*=' - -# -# Soft link creation in case it doesn't exist -# -- name: Check export - ansible.builtin.stat: - path: /export - register: export_status - -- name: Check export home - ansible.builtin.stat: - path: /export/home - when: export_status.stat.exists and export_status.stat.isdir - register: export_home_status - -# -# Before deleting the /export/home directory if the -# home data set is mounted on /export/home if its -# mounted remove if first and then go ahead. -# -- name: Check if the path is mounted - ansible.builtin.shell: | - mount | grep /export/home - register: mount_status - ignore_errors: yes - -- name: Unmount the path if it is mounted - ansible.builtin.mount: - path: /export/home - state: unmounted - when: mount_status.rc == 0 - -- name: Delete home directory - ansible.builtin.file: - path: /export/home - state: absent - when: not export_status.stat.exists or export_home_status.stat.exists and export_home_status.stat.isdir - -- name: Create export directory - ansible.builtin.file: - path: /export - state: directory - mode: 0755 - when: not export_status.stat.exists - -- name: Create the soft link - ansible.builtin.file: - src: /home - dest: /export/home - state: link From 55e6a6f45b9a874287f37faba80b3dc5b3f41cb2 Mon Sep 17 00:00:00 2001 From: Sanjeev Rohila Date: Fri, 18 Apr 2025 15:15:02 +0530 Subject: [PATCH 5/7] Removing the autofs handling as per the concerns raised by Seb and our validation --- debian/preinst | 8 -------- 1 file changed, 8 deletions(-) diff --git a/debian/preinst b/debian/preinst index ff3d7ae21..18e839f1b 100644 --- a/debian/preinst +++ b/debian/preinst @@ -25,20 +25,12 @@ upgrade) # referencing the old /export/home paths continue to function # while also enabling new logins under /home to work. fs_tab=/etc/fstab - auto_master=/etc/auto.master if grep -q "\/export\/home" "$fs_tab"; then sed -i 's|/export/home|/home|g' "$fs_tab" mount /home fi - if [[ -e $auto_master ]]; then - if grep -q "\/home\s+auto_home\s+-nobrowse" "$auto_master"; then - sed -i 's|/home auto_home -nobrowse|#/home auto_home -nobrowse|g' "$auto_master" - systemctl restart autofs - fi - fi - passwd_file=/etc/passwd if grep -q "\/export\/home" "$passwd_file"; then sed -i 's/\/export\/home/\/home/g' /etc/passwd From b1e8b8291f4de55dbcd7587430cf207886ef889e Mon Sep 17 00:00:00 2001 From: Sanjeev Rohila Date: Fri, 18 Apr 2025 15:21:01 +0530 Subject: [PATCH 6/7] Creating a different service for taking care of soft /export/home -> /home --- debian/postinst | 3 +- debian/preinst | 2 +- .../system/delphix-legacy-link.service | 43 +++++++++++++++++++ .../systemd/system/delphix-platform.service | 20 --------- .../roles/delphix-platform/tasks/main.yml | 2 +- 5 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 files/common/lib/systemd/system/delphix-legacy-link.service diff --git a/debian/postinst b/debian/postinst index 9b276316c..734889351 100644 --- a/debian/postinst +++ b/debian/postinst @@ -1,6 +1,6 @@ #!/bin/bash -eux # -# Copyright 2018, 2021 Delphix +# Copyright 2018, 2025 Delphix # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -55,6 +55,7 @@ configure) systemctl enable auditd.service systemctl enable delphix.target systemctl enable delphix-platform.service + systemctl enable delphix-legacy-link.service systemctl enable delphix-rpool-upgrade.service systemctl enable systemd-networkd.service systemctl enable iscsi-name-init.service diff --git a/debian/preinst b/debian/preinst index 18e839f1b..a22ccb233 100644 --- a/debian/preinst +++ b/debian/preinst @@ -1,6 +1,6 @@ #!/bin/bash -eux # -# Copyright 2024 Delphix +# Copyright 2025 Delphix # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/files/common/lib/systemd/system/delphix-legacy-link.service b/files/common/lib/systemd/system/delphix-legacy-link.service new file mode 100644 index 000000000..209f7c6ce --- /dev/null +++ b/files/common/lib/systemd/system/delphix-legacy-link.service @@ -0,0 +1,43 @@ +# +# Copyright 2025 Delphix +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +[Unit] +Description=Create /export/home symlink to /home after platform setup +After=delphix-platform.service +Requires=delphix-platform.service + +[Service] +Type=oneshot +ExecStart=/bin/sh -c '\ + echo "Ensuring /export/home is a symlink to /home..."; \ + if mountpoint -q /export/home; then \ + echo "/export/home is a mountpoint, unmounting..."; \ + umount /export/home || { echo "Failed to unmount /export/home"; exit 1; }; \ + fi; \ + if [ -e /export/home ] && [ ! -L /export/home ]; then \ + echo "Removing existing /export/home directory..."; \ + rm -rf /export/home; \ + fi; \ + if [ ! -d /export ]; then \ + mkdir /export; \ + fi; \ + if [ -d /export ] && [ ! -L /export/home ]; then \ + echo "Creating symlink: /export/home -> /home"; \ + ln -s /home /export/home; \ + fi;' + +[Install] +WantedBy=delphix.target diff --git a/files/common/lib/systemd/system/delphix-platform.service b/files/common/lib/systemd/system/delphix-platform.service index 4dfaa0870..89a809d67 100644 --- a/files/common/lib/systemd/system/delphix-platform.service +++ b/files/common/lib/systemd/system/delphix-platform.service @@ -24,26 +24,6 @@ Before=rsync.service docker.service Type=oneshot ExecStart=/var/lib/delphix-platform/ansible/apply ExecStart=/var/lib/delphix-platform/dynamic-debug - -# Create /export/home symlink to /home if it doesn't already exist -ExecStartPost=/bin/sh -c '\ - echo "Ensuring /export/home is a symlink to /home..."; \ - if mountpoint -q /export/home; then \ - echo "/export/home is a mountpoint, unmounting..."; \ - umount /export/home || { echo "Failed to unmount /export/home"; exit 1; }; \ - fi; \ - if [ -e /export/home ] && [ ! -L /export/home ]; then \ - echo "Removing existing /export/home directory..."; \ - rm -rf /export/home; \ - fi; \ - if [ ! -d /export ]; then \ - mkdir /export; \ - fi; \ - if [ -d /export ] && [ ! -L /export/home ]; then \ - echo "Creating symlink: /export/home -> /home"; \ - ln -s /home /export/home; \ - fi;' - RemainAfterExit=yes # diff --git a/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml b/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml index 893708513..c87ff2bbf 100644 --- a/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml +++ b/files/common/var/lib/delphix-platform/ansible/10-delphix-platform/roles/delphix-platform/tasks/main.yml @@ -1,5 +1,5 @@ # -# Copyright 2018, 2023 Delphix +# Copyright 2018, 2025 Delphix # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. From 8f0067f911a3e2e934a3671904a065db0f1e8601 Mon Sep 17 00:00:00 2001 From: Sanjeev Rohila Date: Mon, 21 Apr 2025 22:16:05 +0530 Subject: [PATCH 7/7] Changing the delphix-legacy-link.service to perform the same steps next reboot like deferred upgrade. --- .../system/delphix-legacy-link.service | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/files/common/lib/systemd/system/delphix-legacy-link.service b/files/common/lib/systemd/system/delphix-legacy-link.service index 209f7c6ce..23b5ec91b 100644 --- a/files/common/lib/systemd/system/delphix-legacy-link.service +++ b/files/common/lib/systemd/system/delphix-legacy-link.service @@ -21,23 +21,25 @@ Requires=delphix-platform.service [Service] Type=oneshot -ExecStart=/bin/sh -c '\ - echo "Ensuring /export/home is a symlink to /home..."; \ - if mountpoint -q /export/home; then \ - echo "/export/home is a mountpoint, unmounting..."; \ - umount /export/home || { echo "Failed to unmount /export/home"; exit 1; }; \ - fi; \ - if [ -e /export/home ] && [ ! -L /export/home ]; then \ - echo "Removing existing /export/home directory..."; \ - rm -rf /export/home; \ - fi; \ - if [ ! -d /export ]; then \ - mkdir /export; \ - fi; \ - if [ -d /export ] && [ ! -L /export/home ]; then \ - echo "Creating symlink: /export/home -> /home"; \ - ln -s /home /export/home; \ - fi;' +ExecStart=/bin/bash -c " \ + if [ ! -L /export/home ]; then \ + echo 'Ensuring /export/home is a symlink to /home...'; \ + if mountpoint -q /export/home; then \ + echo '/export/home is a mountpoint, unmounting...'; \ + umount /export/home || { echo 'Failed to unmount /export/home'; exit 1; }; \ + fi; \ + if [ -e /export/home ]; then \ + echo 'Removing existing /export/home directory...'; \ + rm -rf /export/home; \ + fi; \ + if [ ! -d /export ]; then \ + mkdir /export; \ + fi; \ + if [ -d /export ]; then \ + echo 'Creating symlink: /export/home -> /home'; \ + ln -s /home /export/home; \ + fi; \ + fi" [Install] WantedBy=delphix.target