]>
Commit | Line | Data |
---|---|---|
45794802 SG |
1 | #!/bin/sh |
2 | ||
3 | # lxc: linux Container library | |
4 | ||
5 | # Authors: | |
6 | # Stéphane Graber <stgraber@ubuntu.com> | |
7 | # | |
8 | # This is a test script for lxc-autostart | |
9 | ||
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. | |
14 | ||
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. | |
19 | ||
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 | |
23 | ||
24 | DONE=0 | |
25 | cleanup() { | |
26 | lxc-destroy -n $CONTAINER_NAME >/dev/null 2>&1 || true | |
27 | ||
28 | if [ $DONE -eq 0 ]; then | |
29 | echo "FAIL" | |
30 | exit 1 | |
31 | fi | |
32 | echo "PASS" | |
33 | } | |
34 | ||
35 | trap cleanup EXIT HUP INT TERM | |
36 | set -eu | |
37 | ||
38 | # Create a container | |
39 | CONTAINER_NAME=lxc-test-auto | |
64ea46c7 | 40 | |
bc849355 | 41 | lxc-create -t busybox -n $CONTAINER_NAME -B dir |
7a96a068 | 42 | CONTAINER_PATH=$(dirname $(lxc-info -n $CONTAINER_NAME -c lxc.rootfs.path -H) | sed -e 's/dir://') |
45794802 SG |
43 | cp $CONTAINER_PATH/config $CONTAINER_PATH/config.bak |
44 | ||
45 | # Ensure it's not in lxc-autostart | |
46 | lxc-autostart -L | grep -q $CONTAINER_NAME && \ | |
47 | (echo "Container shouldn't be auto-started" && exit 1) | |
48 | ||
49 | # Mark it as auto-started and re-check | |
50 | echo "lxc.start.auto = 1" >> $CONTAINER_PATH/config | |
51 | lxc-autostart -L | grep -q $CONTAINER_NAME || \ | |
52 | (echo "Container should be auto-started" && exit 1) | |
53 | ||
54 | # Put it in a test group and set a delay | |
55 | echo "lxc.group = lxc-auto-test" >> $CONTAINER_PATH/config | |
56 | echo "lxc.start.delay = 5" >> $CONTAINER_PATH/config | |
57 | ||
58 | # Check that everything looks good | |
59 | if [ "$(lxc-autostart -L -g lxc-auto-test | grep $CONTAINER_NAME)" != "$CONTAINER_NAME 5" ]; then | |
60 | echo "Invalid autostart setting" && exit 1 | |
61 | fi | |
62 | ||
63 | # Start it | |
64 | lxc-autostart -g lxc-auto-test | |
65 | lxc-wait -n $CONTAINER_NAME -t 5 -s RUNNING || (echo "Container didn't start" && exit 1) | |
b7aa56b8 | 66 | sleep 5 |
45794802 SG |
67 | |
68 | # Restart it | |
69 | lxc-autostart -g lxc-auto-test -r | |
70 | lxc-wait -n $CONTAINER_NAME -t 5 -s RUNNING || (echo "Container didn't restart" && exit 1) | |
b7aa56b8 | 71 | sleep 5 |
45794802 | 72 | |
c6b861ba SG |
73 | # When shutting down, the container calls sync. If the machine running |
74 | # the test has a massive backlog, it can take minutes for the sync call to | |
75 | # finish, causing a test failure. | |
76 | # So try to reduce that by flushing everything to disk before we attempt | |
77 | # a container shutdown. | |
78 | sync | |
79 | ||
45794802 | 80 | # Shut it down |
c2997f9e | 81 | lxc-autostart -g lxc-auto-test -s -t 120 |
48356bbf | 82 | lxc-wait -n $CONTAINER_NAME -t 120 -s STOPPED || (echo "Container didn't stop" && exit 1) |
45794802 SG |
83 | |
84 | # Kill it | |
85 | lxc-autostart -g lxc-auto-test -k | |
86 | lxc-wait -n $CONTAINER_NAME -t 60 -s STOPPED || (echo "Container didn't die" && exit 1) | |
87 | ||
88 | DONE=1 |