From 982b93a3d6a44babe598dedf4e04dae388552fc5 Mon Sep 17 00:00:00 2001 From: asela kotagama - aseladk <38081311+AselaDK@users.noreply.github.com> Date: Mon, 16 Aug 2021 17:57:10 +0530 Subject: [PATCH] Added journal user quota for sashi users. (#52) --- dependencies/user-install.sh | 6 +++--- prereq.sh | 23 +++++++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/dependencies/user-install.sh b/dependencies/user-install.sh index 2faa7df..5b0a0e0 100755 --- a/dependencies/user-install.sh +++ b/dependencies/user-install.sh @@ -56,7 +56,7 @@ contract_host_uid=$(expr $uoffset + $contract_uid - 1) contract_host_gid=$(expr $goffset + $contract_gid - 1) groupadd -g "$contract_host_gid" "$contract_user" -useradd --shell /usr/sbin/nologin -M -g "$contract_host_gid" -u "$contract_host_uid" "$contract_user" +useradd --shell /usr/sbin/nologin -M -g "$contract_host_gid" -G "$user" -u "$contract_host_uid" "$contract_user" usermod --lock "$contract_user" echo "Created '$contract_user' contract user." @@ -71,8 +71,8 @@ dockerd_socket="unix://$user_runtime_dir/docker.sock" echo "${memory}K" >/sys/fs/cgroup/memory/$user$cgroupsuffix/memory.limit_in_bytes && echo "${memory}K" >/sys/fs/cgroup/memory/$user$cgroupsuffix/memory.memsw.limit_in_bytes) && rollback "CGROUP_MEM_CREAT" -# Adding disk quota to the new user. -setquota -u -F vfsv0 "$user" "$disk" "$disk" 0 0 / +# Adding disk quota to the group. +setquota -g -F vfsv0 "$user" "$disk" "$disk" 0 0 / echo "Configured the resources" diff --git a/prereq.sh b/prereq.sh index 98894a6..e719cd9 100755 --- a/prereq.sh +++ b/prereq.sh @@ -19,13 +19,24 @@ apt-get update apt install uidmap -y # Check for pattern -# And whether Options is *usrquota* -# If not add usrquota to the options. +# And whether Options is *grpjquota=aquota.group or jqfmt=vfsv0* +# If not add groupquota to the options. updated=0 -sed -n -r -e "/^[^#]\S+\s+\/\s+\S+\s+\S+\s+[0-9]+\s+[0-9]+\s*/{ /^\S+\s+\/\s+\S+\s+\S*usrquota\S*/{q100} }" "$tmpfstab" +sed -n -r -e "/^[^#]\S+\s+\/\s+\S+\s+\S+\s+[0-9]+\s+[0-9]+\s*/{ /^\S+\s+\/\s+\S+\s+\S*grpjquota=aquota.group\S*/{q100} }" "$tmpfstab" res=$? if [ $res -eq 0 ]; then - sed -i -r -e "/^[^#]\S+\s+\/\s+\S+\s+\S+\s+[0-9]+\s+[0-9]+\s*/{ s/^\S+\s+\/\s+\S+\s+\S+/&,usrquota/ }" "$tmpfstab" + sed -i -r -e "/^[^#]\S+\s+\/\s+\S+\s+\S+\s+[0-9]+\s+[0-9]+\s*/{ s/^\S+\s+\/\s+\S+\s+\S+/&,grpjquota=aquota.group/ }" "$tmpfstab" + res=$? + updated=1 +fi + +# If the res is not success(0) or alredy exist(100). +[ ! $res -eq 0 ] && [ ! $res -eq 100 ] && echo "fstab update failed." && exit 1 + +sed -n -r -e "/^[^#]\S+\s+\/\s+\S+\s+\S+\s+[0-9]+\s+[0-9]+\s*/{ /^\S+\s+\/\s+\S+\s+\S*jqfmt=vfsv0\S*/{q100} }" "$tmpfstab" +res=$? +if [ $res -eq 0 ]; then + sed -i -r -e "/^[^#]\S+\s+\/\s+\S+\s+\S+\s+[0-9]+\s+[0-9]+\s*/{ s/^\S+\s+\/\s+\S+\s+\S+/&,jqfmt=vfsv0/ }" "$tmpfstab" res=$? updated=1 fi @@ -47,8 +58,8 @@ else echo "fstab already configured." fi -# Check and turn on user quota if not enabled. -if [ ! -f /aquota.user ]; then +# Check and turn on group quota if not enabled. +if [ ! -f /aquota.group ]; then # quota package is not installed. if ! command -v quota &>/dev/null; then apt-get install -y quota