]> git.proxmox.com Git - mirror_lxc.git/blob - src/tests/lxc-test-checkpoint-restore
spelling: timeout
[mirror_lxc.git] / src / tests / lxc-test-checkpoint-restore
1 #!/bin/sh
2
3 # Do an end to end checkpoint and restore with criu.
4
5 set -e
6
7 FAIL() {
8 echo -n "Failed " >&2
9 echo "$*" >&2
10 exit 1
11 }
12
13 if [ "$(id -u)" != "0" ]; then
14 echo "ERROR: Must run as root."
15 exit 1
16 fi
17
18 verlte() {
19 ! [ "$1" = "$(printf "$1\n$2" | sort -V | tail -n1)" ]
20 }
21
22 criu_version="$(criu --version | head -n1 | cut -d' ' -f 2)"
23
24 if verlte "$criu_version" "1.3.1"; then
25 echo "SKIP: skipping test because no (or wrong) criu installed."
26 exit 0
27 fi
28
29 name=lxc-test-criu
30 lxc-create -t ubuntu -n $name || FAIL "creating container"
31
32 cat >> "$(lxc-config lxc.lxcpath)/$name/config" <<EOF
33 # hax for criu
34 lxc.console.path = none
35 lxc.tty.max = 0
36 lxc.cgroup.devices.deny = c 5:1 rwm
37 EOF
38
39 lxc-start -n $name -d || FAIL "starting container"
40 lxc-wait -n $name -s RUNNING || FAIL "waiting for container to run"
41
42 # Let the container boot and get into a steady state.
43 sleep 5s
44
45 # The first time this usually fails because CRIU cannot checkpoint things with
46 # data on a socket.
47 lxc-checkpoint -n $name -v -s -D /tmp/checkpoint || FAIL "failed checkpointing"
48 lxc-wait -n $name -s STOPPED
49 lxc-checkpoint -n $name -v -r -D /tmp/checkpoint || FAIL "failed restoring"
50
51 lxc-stop -n $name -k
52 lxc-destroy -f -n $name