lxc-test-autostart revision 45794802f13e5db18b5d7acb45169e1f4e8b70b2
2976N/A#!/bin/sh
2976N/A
2976N/A# lxc: linux Container library
2976N/A
2976N/A# Authors:
2976N/A# Stéphane Graber <stgraber@ubuntu.com>
2976N/A#
2976N/A# This is a test script for lxc-autostart
2976N/A
2976N/A# This library is free software; you can redistribute it and/or
2976N/A# modify it under the terms of the GNU Lesser General Public
2976N/A# License as published by the Free Software Foundation; either
2976N/A# version 2.1 of the License, or (at your option) any later version.
2976N/A
2976N/A# This library is distributed in the hope that it will be useful,
2976N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
2976N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2976N/A# Lesser General Public License for more details.
2976N/A
2976N/A# You should have received a copy of the GNU Lesser General Public
2976N/A# License along with this library; if not, write to the Free Software
2976N/A# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2976N/A
2976N/ADONE=0
2976N/Acleanup() {
3215N/A lxc-destroy -n $CONTAINER_NAME >/dev/null 2>&1 || true
5636N/A
2976N/A if [ $DONE -eq 0 ]; then
2976N/A echo "FAIL"
2976N/A exit 1
5636N/A fi
5636N/A echo "PASS"
2976N/A}
2976N/A
2976N/Atrap cleanup EXIT HUP INT TERM
2976N/Aset -eu
3885N/A
3885N/A# Create a container
3885N/ACONTAINER_NAME=lxc-test-auto
2976N/Alxc-create -t download -n $CONTAINER_NAME -- -d ubuntu -r trusty -a i386
2976N/ACONTAINER_PATH=$(dirname $(lxc-info -n $CONTAINER_NAME -c lxc.rootfs -H))
cp $CONTAINER_PATH/config $CONTAINER_PATH/config.bak
# Ensure it's not in lxc-autostart
lxc-autostart -L | grep -q $CONTAINER_NAME && \
(echo "Container shouldn't be auto-started" && exit 1)
# Mark it as auto-started and re-check
echo "lxc.start.auto = 1" >> $CONTAINER_PATH/config
lxc-autostart -L | grep -q $CONTAINER_NAME || \
(echo "Container should be auto-started" && exit 1)
# Put it in a test group and set a delay
echo "lxc.group = lxc-auto-test" >> $CONTAINER_PATH/config
echo "lxc.start.delay = 5" >> $CONTAINER_PATH/config
# Check that everything looks good
if [ "$(lxc-autostart -L -g lxc-auto-test | grep $CONTAINER_NAME)" != "$CONTAINER_NAME 5" ]; then
echo "Invalid autostart setting" && exit 1
fi
# Start it
lxc-autostart -g lxc-auto-test
lxc-wait -n $CONTAINER_NAME -t 5 -s RUNNING || (echo "Container didn't start" && exit 1)
# Restart it
lxc-autostart -g lxc-auto-test -r
lxc-wait -n $CONTAINER_NAME -t 5 -s RUNNING || (echo "Container didn't restart" && exit 1)
# Shut it down
lxc-autostart -g lxc-auto-test -s
lxc-wait -n $CONTAINER_NAME -t 60 -s STOPPED || (echo "Container didn't stop" && exit 1)
# Kill it
lxc-autostart -g lxc-auto-test -k
lxc-wait -n $CONTAINER_NAME -t 60 -s STOPPED || (echo "Container didn't die" && exit 1)
DONE=1