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