volumes: fix various mount related issues

Various notes on mounting:

* The permissions come from the mounted file system and not the mount point.
This means that if we change the perms before mounting, it is overridden by
whatever is in the actual file system.

* uid/gid only works for permission-less file systems

SFTP container notes:

* Assumes that nothing changed if the host path hasn't changed. This means that
if a user changes the disk uuid, reload doesn't work.

* Not sure how/why, but even after unmounting the container can still access the old
mount files (!). With ext4 on disk change or nfs after root path change, the file manager
continues to be able to access the old mounts (despite umount succeeding).

All this led to following changes:

* Remove editing of volumes. Just allow editing username/password.
* edit UI then just also provides a way to re-mount.
* Change mode of mountpoint to be 777 post mounting for ease of use. Otherwise, we have to
make the user do this by ssh. this can always become options later.
This commit is contained in:
Girish Ramakrishnan
2021-06-21 12:11:05 -07:00
parent f433146484
commit 6ace8d1ac5
6 changed files with 46 additions and 72 deletions

View File

@@ -18,6 +18,7 @@ if [[ "$1" == "--check" ]]; then
fi
mount_file_contents="$1"
timeout="$2" # seconds
# mount units must be named after the mount point directories they control
where=$(echo "${mount_file_contents}" | grep "^Where=" | cut -d'=' -f 2)
@@ -25,15 +26,22 @@ where=$(echo "${mount_file_contents}" | grep "^Where=" | cut -d'=' -f 2)
mount_filename=$(systemd-escape -p --suffix=mount "$where")
mount_file="/etc/systemd/system/${mount_filename}"
systemctl stop "${mount_filename}" || true
# cleanup any previous mount of same name (after midway box crash?)
if systemctl -q is-active mnt-volumes-ext4data.mount; then
echo "Previous mount active, unmounting"
systemctl stop "${mount_filename}" || true
fi
echo "$mount_file_contents" > "${mount_file}"
systemctl daemon-reload
# systemd can automatically create the "where" dir but the backup logic relies on permissions
mkdir -p "${where}"
chown yellowtent:yellowtent "${where}" || true # this can fail with nfs+root_squash
chmod 777 "${where}" # this allows all users to read and write
if ! timeout "${timeout}" systemctl enable --now "${mount_filename}"; then
echo "Failed to mount"
exit 1
fi
systemctl enable --no-block --now "${mount_filename}" || true
echo "Mount succeeded"
# this has to be done post-mount because permissions come from the underlying mount file system and not the mount point
chmod 777 "${where}"