Merge "Support BuildFlags: nocumulaterpms" into devel
[tools/build.git] / build-vm-lxc
1 #
2 # LXC specific functions
3 #
4 ################################################################
5 #
6 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2 or 3 as
10 # published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program (see the file COPYING); if not, write to the
19 # Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 #
22 ################################################################
23
24 lxc_get_id() {
25     LXCID="obsbuild:${BUILD_ROOT##*/}"
26 }
27
28 vm_verify_options_lxc() {
29     VM_IMAGE=
30     VM_SWAP=
31 }
32
33 vm_startup_lxc() {
34     lxc_get_id
35     LXCDIR="`lxc-config lxc.lxcpath`/$LXCID"
36     LXCROOTFS="$LXCDIR/rootfs"
37     LXCHOOK="$LXCDIR/pre-mount.hook"
38     LXCCONF="$BUILD_ROOT/.build.lxc.conf"
39     rm -f "$LXCCONF"
40     cat $BUILD_DIR/lxc.conf > "$LXCCONF"
41     cat >> "$LXCCONF" <<-EOF
42         lxc.rootfs = $LXCROOTFS
43         lxc.hook.pre-mount = $LXCHOOK
44         EOF
45     # XXX: do this always instead of leaking the hosts' one?
46     echo "rootfs / rootfs rw 0 0" > $BUILD_ROOT/etc/mtab
47     lxc-destroy -n "$LXCID" >/dev/null 2>&1 || true
48     mkdir -p "$LXCROOTFS"
49     cat > "$LXCHOOK" <<-EOF
50         #!/bin/sh
51         mount --bind "$BUILD_ROOT" "$LXCROOTFS"
52         EOF
53     chmod a+x "$LXCHOOK"
54     case "$(lxc-create --version)" in
55         1.0.8|1.1.*)
56            lxc-create -n "$LXCID" -f "$LXCCONF" -t none || cleanup_and_exit 1
57            lxc-start -n "$LXCID" -F "$vm_init_script"
58            ;;
59         1.0.*)
60            lxc-create -n "$LXCID" -f "$LXCCONF" || cleanup_and_exit 1
61            lxc-start -n "$LXCID" "$vm_init_script"
62            ;;
63     esac
64     BUILDSTATUS="$?"
65     test "$BUILDSTATUS" != 255 || BUILDSTATUS=3
66     cleanup_and_exit "$BUILDSTATUS"
67 }
68
69 vm_kill_lxc() {
70     lxc_get_id
71     lxc-stop -n "$LXCID" || true
72 }
73
74 vm_fixup_lxc() {
75     :
76 }
77
78 vm_attach_root_lxc() {
79     :
80 }
81
82 vm_attach_swap_lxc() {
83     :
84 }
85
86 vm_detach_root_lxc() {
87     :
88 }
89
90 vm_detach_swap_lxc() {
91     :
92 }
93
94 vm_cleanup_lxc() {
95     if test $$ -ne 1 && test $$ -ne 2 ; then
96         lxc_get_id
97         lxc-destroy -n "$LXCID"
98     fi
99 }
100