Commit 3223165c authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

app-test: dump and restore a Linux Container

network-script.sh is used for locking and unlocking network in CT.

Here is an example of an LXC config:
lxc.console=none
lxc.utsname = test-lxc
lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = br0
lxc.network.name = eth0
lxc.mount = /root/test-lxc/etc/fstab
lxc.rootfs = /root/test-lxc-root/
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 5ec8a1c3
#!/bin/bash
[ -z "$CR_IP_TOOL" ] && CR_IP_TOOL=ip
action=$1
shift
[[ "network-unlock" == "$CRTOOLS_SCRIPT_ACTION" ||
"network-lock" == "$CRTOOLS_SCRIPT_ACTION" ]] || exit 0
set -o pipefail
[ "$action" == dump ] && {
pid=$1
name=$2
# Find a pair of CT's eth0
ifindex=`$CR_IP_TOOL netns exec $name ethtool -S eth0 | awk '/index/ { print $2}'`
[ $? -eq 0 ] || exit 1
for i in /sys/devices/virtual/net/*; do
[ "`cat $i/ifindex`" == $ifindex ] && {
dst=`basename $i`
break;
}
done
[ -z "$dst" ] && exit 1
echo "$dst<=>eth0"
[ "network-unlock" == "$CRTOOLS_SCRIPT_ACTION" ] && {
echo Attach $dst to the bridge br0
brctl addif br0 $dst
exit $?
}
[ "network-lock" == "$CRTOOLS_SCRIPT_ACTION" ] && {
echo Detach $dst to the bridge br0
brctl delif br0 $dst
exit $?
}
exit 0
}
[ "$action" == restore ] && {
[ "network-unlock" == "$CRTOOLS_SCRIPT_ACTION" ] && {
ethname=$1
echo Attach $ethname to the bridge br0
ip link set up dev $ethname
brctl addif br0 $ethname
exit $?
}
}
exit 0
#!/bin/bash
[ -z "$CR_IP_TOOL" ] && CR_IP_TOOL=ip
cd `dirname $0`
crtools="../../../crtools"
name=$1
[ -z "$name" ] && { cat <<EOF
Usage: $0 NAME [PID]"
NAME - a container name
PID - PID of the container's "init". It's required, if CT is dumped
in a second time, because LXC tools don't work in this case.
EOF
exit 1;
}
pid=$2
[ -z "$pid" ] && {
lxc-info --name $name || exit 1
pid=$(lxc-info --name $name | awk '/pid:/ { print $2 }')
}
echo "The CT's \"init\" process has PID of $pid"
kill -0 $pid || exit 1
ln -sf /proc/$pid/ns/net /var/run/netns/$name
$CR_IP_TOOL netns exec $name ip a || exit 1
mkdir data
echo "Dump the CT $name ($pid)"
${crtools} dump --evasive-devices \
--tcp-established \
-n net -n mnt -n ipc -n pid \
--action-script "`pwd`/network-script.sh dump $pid $name" \
-vvvv -D data -o dump.log -t $pid || exit 1
echo "The CT $name was dumped successfully"
echo Press Enter for restoring CT
read
echo "Restore the CT $name ($pid)"
${crtools} restore --evasive-devices \
--tcp-established \
-n net -n mnt -n ipc -n pid \
--action-script "`pwd`/network-script.sh restore $name.0" \
--veth-pair eth0=$name.0 \
--root /root/test-lxc-root \
--pidfile newpid.log \
-vvvv -D data -d -o restore.log -t $pid || exit 1
echo "The CT $name was restored successfully"
pid=`cat data/newpid.log`;
echo "The CT's \"init\" process has PID of $pid"
kill -0 $pid || exit 1
ln -sf /proc/$pid/ns/net /var/run/netns/$name
$CR_IP_TOOL netns exec $name ip a || exit 1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment