X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=blobdiff_plain;f=roles%2Fpartfs_rootdisk%2Fscripts%2Fvol_mgmt.sh;h=f99c3fee589dddda16efb9ad91021dad5f12f508;hb=3711c3e8a073609f097d3346acb8add006a6dabc;hp=b1ac984b30df411fcbb0c0027b4f6e066f407e2b;hpb=74a49ba6ef2ea715fa492db0bcd85c30398688e8;p=ta%2Finfra-ansible.git diff --git a/roles/partfs_rootdisk/scripts/vol_mgmt.sh b/roles/partfs_rootdisk/scripts/vol_mgmt.sh index b1ac984..f99c3fe 100755 --- a/roles/partfs_rootdisk/scripts/vol_mgmt.sh +++ b/roles/partfs_rootdisk/scripts/vol_mgmt.sh @@ -17,23 +17,33 @@ # This tool is meant to stop processes running in a given directory. # Evacuate its contents to a temp location. # Mount a given LVM to the Directory +# optionally change ownership of the root of the LVM # Start those services again #arg1: Directory to evacuate #arg2: Volume dev path to mount +#arg3/arg4 (optional, must provide both): owner/group of root directory of new mount exec >> /tmp/vol_mgmt_logfile exec 2>&1 - -if [[ $# != 2 ]];then +if [[ $# == 4 ]];then + evac_dir=$1 + mount_vol_dev=$2 + owner=$3 + group=$4 +elif [[ $# == 2 ]]; then + evac_dir=$1 + mount_vol_dev=$2 + # they didn't provide a u/g. use the owner of the mountpoint if + # it exists or our own user/group (almost certaimly root) if not. + owner=`stat -c '%U' ${evac_dir} 2>/dev/null || id -un` + group=`stat -c '%G' ${evac_dir} 2>/dev/null || id -gn` +else echo "Improper number of arguments passed!!" exit 1 fi -evac_dir=$1 -mount_vol_dev=$2 - echo "Trying to mount $mount_vol_dev on $evac_dir" # Run partprobe to load new volumes @@ -44,6 +54,9 @@ if [ ! -d $evac_dir ];then mkdir -p "$evac_dir" fi +# mirror the permissions of the existing directory +oPerm=`stat -c '%a' ${evac_dir}` +' if [ ! -b $mount_vol_dev ];then echo "Provided volume $mount_vol_dev is not a block device!!" exit 1 @@ -104,6 +117,9 @@ rm -rf ${evac_dir}/* # Mount the volume on dir mount $evac_dir +chown ${owner}:${group} ${evac_dir} +chmod ${oPerm} ${evac_dir} + cp -rpf $tmp_dir/* ${evac_dir}/ rm -rf $tmp_dir