3 # lxc: linux Container library
6 # Stéphane Graber <stgraber@ubuntu.com>
8 # This is a test script for lxc-autostart
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public
12 # License as published by the Free Software Foundation; either
13 # version 2.1 of the License, or (at your option) any later version.
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Lesser General Public License for more details.
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 lxc-destroy
-n $CONTAINER_NAME >/dev
/null
2>&1 || true
28 if [ $DONE -eq 0 ]; then
36 if type dpkg
>/dev
/null
2>&1; then
37 ARCH
=$
(dpkg
--print-architecture)
40 trap cleanup EXIT HUP INT TERM
44 CONTAINER_NAME
=lxc-test-auto
45 lxc-create
-t download
-n $CONTAINER_NAME -- -d ubuntu
-r trusty
-a $ARCH
46 CONTAINER_PATH
=$
(dirname $
(lxc-info
-n $CONTAINER_NAME -c lxc.rootfs
-H))
47 cp $CONTAINER_PATH/config
$CONTAINER_PATH/config.bak
49 # Ensure it's not in lxc-autostart
50 lxc-autostart
-L |
grep -q $CONTAINER_NAME && \
51 (echo "Container shouldn't be auto-started" && exit 1)
53 # Mark it as auto-started and re-check
54 echo "lxc.start.auto = 1" >> $CONTAINER_PATH/config
55 lxc-autostart
-L |
grep -q $CONTAINER_NAME || \
56 (echo "Container should be auto-started" && exit 1)
58 # Put it in a test group and set a delay
59 echo "lxc.group = lxc-auto-test" >> $CONTAINER_PATH/config
60 echo "lxc.start.delay = 5" >> $CONTAINER_PATH/config
62 # Check that everything looks good
63 if [ "$(lxc-autostart -L -g lxc-auto-test | grep $CONTAINER_NAME)" != "$CONTAINER_NAME 5" ]; then
64 echo "Invalid autostart setting" && exit 1
68 lxc-autostart
-g lxc-auto-test
69 lxc-wait
-n $CONTAINER_NAME -t 5 -s RUNNING ||
(echo "Container didn't start" && exit 1)
73 lxc-autostart
-g lxc-auto-test
-r
74 lxc-wait
-n $CONTAINER_NAME -t 5 -s RUNNING ||
(echo "Container didn't restart" && exit 1)
77 # When shutting down, the container calls sync. If the machine running
78 # the test has a massive backlog, it can take minutes for the sync call to
79 # finish, causing a test failure.
80 # So try to reduce that by flushing everything to disk before we attempt
81 # a container shutdown.
85 lxc-autostart
-g lxc-auto-test
-s -t 120
86 lxc-wait
-n $CONTAINER_NAME -t 120 -s STOPPED ||
(echo "Container didn't stop" && exit 1)
89 lxc-autostart
-g lxc-auto-test
-k
90 lxc-wait
-n $CONTAINER_NAME -t 60 -s STOPPED ||
(echo "Container didn't die" && exit 1)