Periodically send signal to trigger qemu-img to show current progress

This commit is contained in:
Gennady Lipenkov 2020-12-10 18:50:28 +03:00
parent 992cbe6dee
commit d0367d90bd
3 changed files with 17 additions and 3 deletions

View File

@ -63,7 +63,7 @@ if ! WaitFile "${DISK_EXPORT_PATH}"; then
fi
echo "Dumping disk..."
if ! qemu-img convert -p -O qcow2 -o cluster_size=2M "${DISK_EXPORT_PATH}" disk.qcow2; then
if ! qemu-img convert -O qcow2 -o cluster_size=2M "${DISK_EXPORT_PATH}" disk.qcow2; then
echo "Failed to dump disk to qcow2 image."
Exit 1
fi

View File

@ -59,7 +59,7 @@ if ! WaitFile "${DISK_EXPORT_PATH}"; then
fi
echo "Dumping disk..."
if ! qemu-img convert -p -O qcow2 -o cluster_size=2M "${DISK_EXPORT_PATH}" disk.qcow2; then
if ! qemu-img convert -O qcow2 -o cluster_size=2M "${DISK_EXPORT_PATH}" disk.qcow2; then
echo "Failed to dump disk to qcow2 image."
Exit 1
fi

View File

@ -54,7 +54,21 @@ func (s *StepWaitCloudInitScript) Run(ctx context.Context, state multistep.State
ui.Error(err.Error())
return
}
ui.Message("Init output closed")
ui.Message("Cloud-init output closed")
}()
// periodically show progress by sending SIGUSR1 to `qemu-img` process
go func() {
cmd := &packersdk.RemoteCmd{
Command: "until pid=$(pidof qemu-img) ; do sleep 1 ; done ; " +
"while true ; do sudo kill -s SIGUSR1 ${pid}; sleep 10 ; done",
}
err := cmd.RunWithUi(ctxWithCancel, comm, ui)
if err != nil && !errors.Is(err, context.Canceled) {
ui.Error("qemu-img signal sender error: " + err.Error())
return
}
}()
// Keep checking the serial port output to see if the cloud-init script is done.