root / snf-image-host / xen-common.sh @ 971a3e68
History | View | Annotate | Download (2.8 kB)
1 |
# Copyright (C) 2013 GRNET S.A. |
---|---|
2 |
# |
3 |
# This program is free software; you can redistribute it and/or modify |
4 |
# it under the terms of the GNU General Public License as published by |
5 |
# the Free Software Foundation; either version 2 of the License, or |
6 |
# (at your option) any later version. |
7 |
# |
8 |
# This program is distributed in the hope that it will be useful, but |
9 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 |
# General Public License for more details. |
12 |
# |
13 |
# You should have received a copy of the GNU General Public License |
14 |
# along with this program; if not, write to the Free Software |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
16 |
# 02110-1301, USA. |
17 |
|
18 |
get_img_dev() { |
19 |
echo /dev/xvdb |
20 |
} |
21 |
|
22 |
launch_helper() { |
23 |
local name helperid rc blockdev floppy |
24 |
|
25 |
blockdev="$1" |
26 |
floppy="$2" |
27 |
|
28 |
name="snf-image-helper-$instance-$RANDOM" |
29 |
|
30 |
report_info "Starting customization VM..." |
31 |
echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM START" >&2 |
32 |
|
33 |
xm create /dev/null \ |
34 |
kernel="$HELPER_DIR/kernel" ramdisk="$HELPER_DIR/initrd" \ |
35 |
root="/dev/xvda1" memory="$HELPER_MEMORY" boot="c" vcpus=1 name="$name" \ |
36 |
extra="console=hvc0 hypervisor=$HYPERVISOR snf_image_activate_helper \ |
37 |
ipv6.disable=1 rules_dev=/dev/xvdc ro boot=local helper_ip=10.0.0.1 \ |
38 |
monitor_port=48888 init=/usr/bin/snf-image-helper" \ |
39 |
disk="file:$HELPER_DIR/image,xvda,r" disk="phy:$blockdev,xvdb,w" \ |
40 |
disk="file:$floppy,xvdc,r" vif="script=${XEN_SCRIPTS_DIR}/vif-snf-image" |
41 |
add_cleanup suppress_errors xm destroy "$name" |
42 |
|
43 |
if ! xenstore-exists snf-image-helper; then |
44 |
xenstore-write snf-image-helper "" |
45 |
#add_cleanup xenstore-rm snf-image-helper |
46 |
fi |
47 |
|
48 |
helperid=$(xm domid "$name") |
49 |
xenstore-write snf-image-helper/${helperid} "" |
50 |
add_cleanup xenstore-rm snf-image-helper/${helperid} |
51 |
xenstore-chmod snf-image-helper/${helperid} r0 w${helperid} |
52 |
|
53 |
filter='udp and dst port 48888 and dst host 10.0.0.255 and src host 10.0.0.1' |
54 |
$TIMEOUT -k $HELPER_HARD_TIMEOUT $HELPER_SOFT_TIMEOUT \ |
55 |
./helper-monitor.py -i "vif${helperid}.0" -f "$filter" ${MONITOR_FD} & |
56 |
monitor_pid=$! |
57 |
|
58 |
set +e |
59 |
$TIMEOUT -k $HELPER_HARD_TIMEOUT $HELPER_SOFT_TIMEOUT \ |
60 |
socat EXEC:"xm console $name",pty STDOUT | sed -u 's|^|HELPER: |g' |
61 |
rc=$? |
62 |
set -e |
63 |
|
64 |
echo "$($DATE +%Y:%m:%d-%H:%M:%S.%N) VM STOP" >&2 |
65 |
|
66 |
check_helper_rc "$rc" |
67 |
|
68 |
set +e |
69 |
wait "$monitor_pid" |
70 |
monitor_rc=$? |
71 |
set -e |
72 |
|
73 |
if [ $monitor_rc -ne 0 ]; then |
74 |
log_error "Helper VM monitoring failed" |
75 |
report_error "Helper VM monitoring failed" |
76 |
exit 1 |
77 |
fi |
78 |
|
79 |
report_info "Checking customization status..." |
80 |
result=$(xenstore-read snf-image-helper/$helperid) |
81 |
report_info "Customization status is: $result" |
82 |
|
83 |
check_helper_result "$result" |
84 |
} |
85 |
|
86 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |