From d0ba9f9c140fbdec9dd3ba2ee780b0426ce313d4 Mon Sep 17 00:00:00 2001 From: Sanjeev Rohila Date: Thu, 11 Jul 2024 15:32:45 +0530 Subject: [PATCH] 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 00000000..0278f46c --- /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 36f1956a..5ae9342f 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