]>
Commit | Line | Data |
---|---|---|
735f2c6e TA |
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 | ||
5f845c92 TA |
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 | ||
d48d2229 | 24 | if verlte "$criu_version" "1.3.1"; then |
735f2c6e TA |
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 | |
3aed4934 | 34 | lxc.console.path = none |
fe1c5887 | 35 | lxc.tty.max = 0 |
735f2c6e TA |
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" | |
da0e298c | 48 | lxc-wait -n $name -s STOPPED |
735f2c6e TA |
49 | lxc-checkpoint -n $name -v -r -D /tmp/checkpoint || FAIL "failed restoring" |
50 | ||
09ef0838 | 51 | lxc-stop -n $name -k |
735f2c6e | 52 | lxc-destroy -f -n $name |