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
25 KNOWN_RELEASES
="precise trusty xenial yakkety zesty"
27 lxc-destroy
-n $CONTAINER_NAME >/dev
/null
2>&1 || true
29 if [ $DONE -eq 0 ]; then
37 if type dpkg
>/dev
/null
2>&1; then
38 ARCH
=$
(dpkg
--print-architecture)
41 trap cleanup EXIT HUP INT TERM
45 CONTAINER_NAME
=lxc-test-auto
47 # default release is trusty, or the systems release if recognized
49 if [ -f /etc
/lsb-release
]; then
51 rels
=$
(ubuntu-distro-info
--supported 2>/dev
/null
) ||
52 rels
="$KNOWN_RELEASES"
54 [ "$DISTRIB_CODENAME" = "$r" ] && release
="$r"
58 lxc-create
-t download
-n $CONTAINER_NAME -B dir
-- -d ubuntu
-r $release -a $ARCH
59 CONTAINER_PATH
=$
(dirname $
(lxc-info
-n $CONTAINER_NAME -c lxc.rootfs.path
-H) |
sed -e 's/dir://')
60 cp $CONTAINER_PATH/config
$CONTAINER_PATH/config.bak
62 # Ensure it's not in lxc-autostart
63 lxc-autostart
-L |
grep -q $CONTAINER_NAME && \
64 (echo "Container shouldn't be auto-started" && exit 1)
66 # Mark it as auto-started and re-check
67 echo "lxc.start.auto = 1" >> $CONTAINER_PATH/config
68 lxc-autostart
-L |
grep -q $CONTAINER_NAME || \
69 (echo "Container should be auto-started" && exit 1)
71 # Put it in a test group and set a delay
72 echo "lxc.group = lxc-auto-test" >> $CONTAINER_PATH/config
73 echo "lxc.start.delay = 5" >> $CONTAINER_PATH/config
75 # Check that everything looks good
76 if [ "$(lxc-autostart -L -g lxc-auto-test | grep $CONTAINER_NAME)" != "$CONTAINER_NAME 5" ]; then
77 echo "Invalid autostart setting" && exit 1
81 lxc-autostart
-g lxc-auto-test
82 lxc-wait
-n $CONTAINER_NAME -t 5 -s RUNNING ||
(echo "Container didn't start" && exit 1)
86 lxc-autostart
-g lxc-auto-test
-r
87 lxc-wait
-n $CONTAINER_NAME -t 5 -s RUNNING ||
(echo "Container didn't restart" && exit 1)
90 # When shutting down, the container calls sync. If the machine running
91 # the test has a massive backlog, it can take minutes for the sync call to
92 # finish, causing a test failure.
93 # So try to reduce that by flushing everything to disk before we attempt
94 # a container shutdown.
98 lxc-autostart
-g lxc-auto-test
-s -t 120
99 lxc-wait
-n $CONTAINER_NAME -t 120 -s STOPPED ||
(echo "Container didn't stop" && exit 1)
102 lxc-autostart
-g lxc-auto-test
-k
103 lxc-wait
-n $CONTAINER_NAME -t 60 -s STOPPED ||
(echo "Container didn't die" && exit 1)