summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-03 20:36:09 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-03 20:36:09 +0900
commit6fd4e6e2545eca2b7ed812f0922066c343dbd54c (patch)
treee5b9d31f8f9297035ceb249e91ee66e80574b391
parentede78f49b96825194f41e2264e807c95eea8d88a (diff)
downloadbuildstream-6fd4e6e2545eca2b7ed812f0922066c343dbd54c.tar.gz
ostree-pull-sh, ostree-push: Graceful termination on SIGTERM.
-rwxr-xr-xbuildstream/data/ostree-pull-ssh25
-rwxr-xr-xbuildstream/data/ostree-push25
2 files changed, 40 insertions, 10 deletions
diff --git a/buildstream/data/ostree-pull-ssh b/buildstream/data/ostree-pull-ssh
index 3bc5793b8..364e6ae93 100755
--- a/buildstream/data/ostree-pull-ssh
+++ b/buildstream/data/ostree-pull-ssh
@@ -96,17 +96,32 @@ fi
# Exit handler
cleanup() {
if [ -n "$remote_repo" ]; then
- if mountpoint "$remote_repo" > /dev/null; then
- fusermount -u "$remote_repo"
- fi
- rm -rf "$remote_repo"
+ if [ ! -z "$sshfs_pid" ]; then
+ kill -TERM "$sshfs_pid"
+ wait "$sshfs_pid"
+
+ touch "killed_sshfs"
+ fi
+
+ # This is just unreliable, sleep 2 and retry seems to fix
+ # the case of forceful termination
+ fusermount -u "$remote_repo" || true
+ sleep 2
+ fusermount -u "$remote_repo" || true
+
+ rmdir "$remote_repo"
fi
}
trap cleanup EXIT
+trap cleanup TERM
# Mount the remote repo
remote_repo=$(mktemp -d ostree-pull.XXXXXXXXXX)
-sshfs "$remote_repo" "$REMOTE"
+
+sshfs "$remote_repo" "$REMOTE" &
+sshfs_pid="$!"
+wait "$sshfs_pid"
+sshfs_pid=""
# Use pull-local to emulate pushing
ostree pull-local --repo="$OSTREE_REPO" "${PULL_ARGS[@]}" "$remote_repo" "$@"
diff --git a/buildstream/data/ostree-push b/buildstream/data/ostree-push
index 9d7120b26..a80db416e 100755
--- a/buildstream/data/ostree-push
+++ b/buildstream/data/ostree-push
@@ -96,17 +96,32 @@ fi
# Exit handler
cleanup() {
if [ -n "$remote_repo" ]; then
- if mountpoint "$remote_repo" > /dev/null; then
- fusermount -u "$remote_repo"
- fi
- rm -rf "$remote_repo"
+ if [ ! -z "$sshfs_pid" ]; then
+ kill -TERM "$sshfs_pid"
+ wait "$sshfs_pid"
+
+ touch "killed_sshfs"
+ fi
+
+ # This is just unreliable, sleep 2 and retry seems to fix
+ # the case of forceful termination
+ fusermount -u "$remote_repo" || true
+ sleep 2
+ fusermount -u "$remote_repo" || true
+
+ rmdir "$remote_repo"
fi
}
trap cleanup EXIT
+trap cleanup TERM
# Mount the remote repo
remote_repo=$(mktemp -d ostree-push.XXXXXXXXXX)
-sshfs "$remote_repo" "$REMOTE"
+
+sshfs "$remote_repo" "$REMOTE" &
+sshfs_pid="$!"
+wait "$sshfs_pid"
+sshfs_pid=""
# Use pull-local to emulate pushing
ostree pull-local --repo="$remote_repo" "${PULL_ARGS[@]}" "$OSTREE_REPO" "$@"