summaryrefslogtreecommitdiff
path: root/build-vm-xen
blob: 736600926e30ceb27adfc735469de422dd11502b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#
# XEN specific functions
#
################################################################
#
# Copyright (c) 1995-2014 SUSE Linux Products GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################

vm_verify_options_xen() {
    vm_kernel=/boot/vmlinuz
    vm_initrd=/boot/initrd
    test -e /boot/vmlinuz-xen && vm_kernel=/boot/vmlinuz-xen
    test -e /boot/initrd-xen && vm_initrd=/boot/initrd-xen
    test -n "$VM_KERNEL" && vm_kernel="$VM_KERNEL"
    test -n "$VM_INITRD" && vm_initrd="$VM_INITRD"
}

vm_startup_xen() {
    XMCMD=xm
    test ! -x /usr/sbin/xm -a -x /usr/sbin/xl && XMCMD=xl
    XMROOT="file:$(readlink -f $VM_IMAGE)"
    XMROOT=${XMROOT/#file:\/dev/phy:/dev}
    XMROOT="disk=$XMROOT,hda1,w"
    XMSWAP=
    if test -n "$VM_SWAP" ; then
	XMSWAP="file:$(readlink -f $VM_SWAP)"
	XMSWAP=${XMSWAP/#file:\/dev/phy:/dev}
	XMSWAP="disk=$XMSWAP,hda2,w"
    fi
    XENID="${VM_IMAGE%/root}"
    XENID="${XENID%/tmpfs}"
    XENID="${XENID##*/}"
    XENID="${XENID#root_}"

    if $XMCMD list "build_$XENID" >/dev/null 2>&1 ; then
       echo "Instance already exists, something really went wrong..."
       echo "Please report to your server admin, there might be multiple services running for same domain"
       cleanup_and_exit 3
    fi
    XEN_CONF_FILE=`mktemp /var/tmp/build.xen.conf-XXXXXXXXX` || cleanup_and_exit 3
    
    echo "kernel = \"$vm_kernel\""                                           >  $XEN_CONF_FILE
    echo "ramdisk = \"$vm_initrd\""                                          >> $XEN_CONF_FILE
    echo "memory = ${VM_MEMSIZE:-64}"                                        >> $XEN_CONF_FILE
    test -n "$BUILD_JOBS" && echo "vcpus = $BUILD_JOBS"                      >> $XEN_CONF_FILE
    echo "root = \"/dev/hda1 ro\""                                           >> $XEN_CONF_FILE
    echo "extra = \"init=/bin/bash console=ttyS0 panic=1 udev_timeout=360\"" >> $XEN_CONF_FILE
    echo "on_poweroff = \"destroy\""                                         >> $XEN_CONF_FILE
    echo "on_reboot = \"destroy\""                                           >> $XEN_CONF_FILE
    echo "on_crash = \"destroy\""                                            >> $XEN_CONF_FILE
    if test "$XMCMD" = xm ; then
	set -- xm create -c $XEN_CONF_FILE name="build_$XENID" $XMROOT $XMSWAP extra="panic=1 quiet init="$vm_init_script" rd.driver.pre=binfmt_misc elevator=noop console=ttyS0"
    else
	XLDISK=
	XLDISK="\"${XMROOT#disk=}\""
	test -n "$XMSWAP" && XLDISK="$XLDISK, \"${XMSWAP#disk=}\""
	set -- xl create -c $XEN_CONF_FILE name="\"build_$XENID\"" "disk=[ $XLDISK ]" extra=\""panic=1 quiet init="$vm_init_script" rd.driver.pre=binfmt_misc elevator=noop console=ttyS0"\"
    fi
    if test "$PERSONALITY" != 0 ; then
	# have to switch back to PER_LINUX to make xm work
	set -- linux64 "$@"
    fi
    echo "$@"
    "$@" || cleanup_and_exit 3
    rm -f "$XEN_CONF_FILE"
}

vm_kill_xen() {
    XMCMD=xm
    test ! -x /usr/sbin/xm -a -x /usr/sbin/xl && XMCMD=xl
    XENID="${VM_IMAGE%/root}"
    XENID="${XENID%/tmpfs}"
    XENID="${XENID##*/}"
    XENID="${XENID#root_}"
    if $XMCMD list "build_$XENID" >/dev/null 2>&1 ; then 
	if ! $XMCMD destroy "build_$XENID" ; then 
	    echo "could not kill xen build $XENID"
	    cleanup_and_exit 1
	fi
    fi
}

# XEN only
vm_purge_xen() {
    # this should not be needed, but sometimes a xen instance gets lost
    XMCMD=xm
    test ! -x /usr/sbin/xm -a -x /usr/sbin/xl && XMCMD=xl
    XENID="${VM_IMAGE%/root}"
    XENID="${XENID%/tmpfs}"
    XENID="${XENID##*/}"
    XENID="${XENID#root_}"
    $XMCMD destroy "build_$XENID" >/dev/null 2>&1
}

vm_fixup_xen() {
    :
}

vm_attach_root_xen() {
    :
}

vm_attach_swap_xen() {
    :
}

vm_detach_root_xen() {
    :
}

vm_detach_swap_xen() {
    :
}

vm_cleanup_xen() {
    :
}