In xen use the helper image in ro mode
[snf-image] / snf-image-host / xen-common.sh
1 get_img_dev() {
2         echo /dev/xvdb
3 }
4
5 launch_helper() {
6         local name helperid rc blockdev floppy
7
8         blockdev="$1"
9         floppy="$2"
10
11         name=$(uuid)
12
13         report_info "Starting customization VM..."
14         echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM START" >&2
15
16     xm create /dev/null \
17       kernel="$HELPER_DIR/kernel-xen" ramdisk="$HELPER_DIR/initrd-xen" \
18           root="/dev/xvda1" memory="256" boot="c" vcpus=1 name="$name" \
19       extra="console=hvc0 hypervisor=$HYPERVISOR snf_image_activate_helper \
20       rules_dev=/dev/xvdc quiet ro boot=local init=/usr/bin/snf-image-helper" \
21       disk="file:$HELPER_DIR/image,xvda,r" disk="phy:$blockdev,xvdb,w" \
22       disk="file:$floppy,xvdc,r" vif="mac=aa:00:00:00:00:11,bridge=$XEN_BRIDGE" \
23
24     if ! xenstore-exists snf-image-helper; then
25         xenstore-write snf-image-helper ""
26                 #add_cleanup xenstore-rm snf-image-helper
27     fi
28
29     helperid=$(xm domid "$name")
30     xenstore-write snf-image-helper/${helperid} ""
31         add_cleanup xenstore-rm snf-image-helper/${helperid}
32     xenstore-chmod snf-image-helper/${helperid} r0 w${helperid}
33
34     brctl delif xenbr "vif${helperid}.0"
35
36     socat EXEC:"./helper-monitor.py ${MONITOR_FD}" INTERFACE:vif${helperid}.0 &
37
38         set +e
39
40     $TIMEOUT -k $HELPER_HARD_TIMEOUT $HELPER_SOFT_TIMEOUT \
41       socat EXEC:"xm console $name",pty STDOUT | sed -u 's|^|HELPER: |g'
42
43         rc=$?
44         set -e
45
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."
60         else
61             log_error "Customization VM died unexpectedly (return code $rc)."
62         fi
63         exit 1
64     else
65         report_info "Customization VM exited normally."
66     fi
67
68     report_info "Checking customization status..."
69     result=$(xenstore-read snf-image-helper/$helperid)
70     report_info "Customization status is: $result"
71
72     if [ "x$result" != "xSUCCESS" ]; then
73         log_error "Image customization failed."
74         report_error "Image customization failed."
75         exit 1
76     fi
77 }
78