From 4a3d3e7a43f9e8e9579a26098e0aa00782cd8896 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Mon, 30 Aug 2021 17:45:46 +1000 Subject: [PATCH] Modify systemd unit and beesd.in to use private mnt namespace to: - avoid influencing the global mount namespace - auto umount upon exit of this unit Signed-off-by: Jiahao XU --- scripts/beesd.in | 8 ++------ scripts/beesd@.service.in | 2 ++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/beesd.in b/scripts/beesd.in index 8072d47..7b65ffc 100755 --- a/scripts/beesd.in +++ b/scripts/beesd.in @@ -111,11 +111,7 @@ mkdir -p "$WORK_DIR" || exit 1 INFO "MOUNT DIR: $MNT_DIR" mkdir -p "$MNT_DIR" || exit 1 -umount_w(){ mountpoint -q "$1" && umount -l "$1"; } -force_umount(){ umount_w "$MNT_DIR"; } -trap force_umount SIGINT SIGTERM EXIT - -mount -osubvolid=5 -o "$MOUNT_OPTIONS" /dev/disk/by-uuid/$UUID "$MNT_DIR" || exit 1 +mount --make-private -osubvolid=5 -o "$MOUNT_OPTIONS" /dev/disk/by-uuid/$UUID "$MNT_DIR" || exit 1 if [ ! -d "$BEESHOME" ]; then INFO "Create subvol $BEESHOME for store bees data" @@ -144,4 +140,4 @@ fi MNT_DIR="$(realpath $MNT_DIR)" cd "$MNT_DIR" -"$bees_bin" "${ARGUMENTS[@]}" $OPTIONS "$MNT_DIR" +exec "$bees_bin" "${ARGUMENTS[@]}" $OPTIONS "$MNT_DIR" diff --git a/scripts/beesd@.service.in b/scripts/beesd@.service.in index b37273c..8ca6ae7 100644 --- a/scripts/beesd@.service.in +++ b/scripts/beesd@.service.in @@ -20,5 +20,7 @@ Restart=on-abnormal StartupCPUWeight=25 StartupIOWeight=25 +PrivateMounts=true + [Install] WantedBy=basic.target