From: dave kormann Date: Fri, 18 Sep 2020 18:39:49 +0000 (-0400) Subject: FIX: Change ownership of newly-created VGs X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=ta%2Finfra-ansible.git;a=commitdiff_plain;h=76de2b3e9925960e461fd7d26e6cc1d00063078e FIX: Change ownership of newly-created VGs When creating a new volume group, allow a user/group to be specified to own the root directory. If no user/group is provided, use the owner of the mountpoint or (if it doesn't exist) the current user/group. This should fix the problem with mariadb permission problems when installing to a vg, as opposed to the existing directory in the image. signed-off-by: dave korman Change-Id: Idf4418dca288a374c53fa6c180c3bdf62db10abb --- diff --git a/roles/partfs_rootdisk/scripts/vol_mgmt.sh b/roles/partfs_rootdisk/scripts/vol_mgmt.sh index b1ac984..85214fe 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 @@ -104,6 +114,8 @@ rm -rf ${evac_dir}/* # Mount the volume on dir mount $evac_dir +chown ${owner}:${group} ${evac_dir} + cp -rpf $tmp_dir/* ${evac_dir}/ rm -rf $tmp_dir