Damans227 commented on code in PR #12843:
URL: https://github.com/apache/cloudstack/pull/12843#discussion_r4351742182
##########
scripts/vm/hypervisor/kvm/nasbackup.sh:
##########
@@ -617,16 +671,29 @@ cleanup() {
exit $EXIT_CLEANUP_FAILED
fi
- rm -rf "$dest" || { echo "Failed to delete $dest"; status=1; }
- umount "$mount_point" || { echo "Failed to unmount $mount_point"; status=1; }
- rmdir "$mount_point" || { echo "Failed to remove mount point $mount_point";
status=1; }
+ if [[ -n "$dest" && -d "$dest" ]]; then
+ rm -rf "$dest" || { echo "Failed to delete $dest"; status=1; }
+ fi
+ if [[ -n "$mount_point" && -d "$mount_point" ]]; then
+ # Only umount if it is actually a mount. Otherwise (mount failed, or
stats/delete
+ # already unmounted) a umount error would wrongly flag cleanup as failed
via the EXIT trap.
+ if mountpoint -q "$mount_point"; then
+ umount "$mount_point" 2>/dev/null || { echo "Failed to unmount
$mount_point"; status=1; }
+ fi
+ rmdir "$mount_point" 2>/dev/null || true
+ fi
if [[ $status -ne 0 ]]; then
echo "Backup cleanup failed"
exit $EXIT_CLEANUP_FAILED
fi
}
+# Trap ensures cleanup runs on any exit path, including SIGTERM/SIGINT and
+# unexpected errors caught by set -e, not just the explicit failure branches.
+# Prevents orphan NFS mounts from accumulating after non-graceful exits.
+trap cleanup EXIT
Review Comment:
that covers it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]