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