Commit e6708890 authored by Arie Peterson's avatar Arie Peterson 🐚
Browse files

Wait for device file after attaching disk

parent fc5fd6be
......@@ -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
......@@ -154,6 +175,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