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