Commit 38d3f46e authored by Maarten de Waard's avatar Maarten de Waard 🤘🏻
Browse files

Merge branch '13-allow-more-time-for-disk-operations' into 'master'

Resolve "Allow more time for disk operations"

Closes #13

See merge request !7
parents 4ad77e39 b1ac3d75
Pipeline #10814 passed with stages
in 1 minute and 15 seconds
......@@ -114,6 +114,27 @@ ghostAction() {
diskSlot=$(jq '."disk_slot"' <<<"$response")
}
waitForFile() {
local filePath=$1
local timeout=$2
local counter=0
while true
do
if [[ -e "$filePath" ]]
then
# File is found.
return 0
fi
sleep 1
((++counter))
if [ $counter -ge $timeout ]
then
# Timeout has elapsed, giving up.
return 1
fi
done
}
domount() {
debug "domount $@"
local mountPath=$1
......@@ -130,6 +151,12 @@ domount() {
then
exitWithFailure "$errorMessage"
fi
# Wait a little while, so that if the disk is in fact reattached to the
# same VPS, the VPS kernel gets a chance to recognise that the disk is gone
# before it is reinserted again.
sleep 1
# Now tell Cosmos2 to attach the disk to the right VPS.
if ! ghostAction "attach" "$apiToken" "$diskID" "$vpsID"
then
......@@ -154,6 +181,16 @@ domount() {
diskLetter=$(printf \\$(printf '%03o' $((97 + $diskSlot))))
device="/dev/xvd${diskLetter}1"
debug "device: $device"
# Wait for the device file to appear. It might take the VPS kernel some
# time to realise that a disk has been attached.
timeout=30
if ! waitForFile "$device" $timeout
then
errorMessage="Device $device did not appear in $timeout seconds."
exitWithFailure "$errorMessage"
fi
# Use the `blkid` program to scan the device for an existing filesystem.
if ! existingFileSystem=$(lsblk -n -o FSTYPE "$device" 2>&1)
then
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment