7 local jail result_file result snapshot rc floppy blockdev
12 # Invoke the helper vm to do the dirty job...
13 jail=$(mktemp -d --tmpdir tmpfsXXXXXXX)
14 add_cleanup rmdir "$jail"
16 mount tmpfs -t tmpfs "$jail" -o size=1G
17 add_cleanup umount -l "$jail"
19 result_file=$(mktemp --tmpdir="$jail" result.XXXXXX)
20 add_cleanup rm "$result_file"
22 snapshot=$(mktemp --tmpdir="$jail" helperXXXXXX.img)
23 add_cleanup rm "$snapshot"
25 "$QEMU_IMG" create -f qcow2 -b "$HELPER_IMG" "$snapshot"
27 report_info "Starting customization VM..."
28 echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM START" >&2
32 $TIMEOUT -k "$HELPER_HARD_TIMEOUT" "$HELPER_SOFT_TIMEOUT" \
33 kvm -runas "$HELPER_USER" -drive file="$snapshot" \
34 -drive file="$blockdev",format=raw,if=virtio,cache=none \
35 -boot c -serial stdio -serial "file:$(printf "%q" "$result_file")" \
36 -serial file:>(./helper-monitor.py ${MONITOR_FD}) \
37 -fda "$floppy" -vga none -nographic -parallel none -monitor null \
38 -kernel "$HELPER_DIR/kernel" -initrd "$HELPER_DIR/initrd" \
39 -append "quiet ro root=/dev/sda1 console=ttyS0,9600n8 \
40 hypervisor=$HYPERVISOR snf_image_activate_helper \
41 rules_dev=/dev/fd0 init=/usr/bin/snf-image-helper" \
42 2>&1 | sed -u 's|^|HELPER: |g'
46 echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM STOP" >&2
47 if [ $rc -ne 0 ]; then
48 if [ $rc -eq 124 ]; then
49 log_error "Customization VM was terminated. Did not finish on time."
50 report_error "Image customization failed. Did not finish on time."
51 elif [ $rc -eq 137 ]; then # (128 + SIGKILL)
52 log_error "Customization VM was killed. Did not finish on time."
53 report_error "Image customization failed. Did not finish on time."
54 elif [ $rc -eq 141 ]; then # (128 + SIGPIPE)
55 log_error "Customization VM was terminated by a SIGPIPE."
56 log_error "Maybe progress monitor has died unexpectedly."
57 elif [ $rc -eq 125 ]; then
58 log_error "Internal Error. Image customization could not start."
59 log_error "timeout did not manage to run."
61 log_error "Customization VM died unexpectedly (return code $rc)."
65 report_info "Customization VM exited normally."
68 report_info "Checking customization status..."
69 # Read the first line. This will remove \r and \n chars
70 result=$(sed 's|\r||g' "$result_file" | head -1)
71 report_info "Customization status is: $result"
73 if [ "x$result" != "xSUCCESS" ]; then
74 log_error "Image customization failed."
75 report_error "Image customization failed."
80 # vim: set sta sts=4 shiftwidth=4 sw=4 et ai :