#!/bin/bash
#
# $Id$
#
# Copyright ITEG IT-Engineers GmbH 2016

# re-starts an LXC container by calling lcu-stop and lcu-start on it, with a slight sleep inbetween

if [ -z "$1" ] ; then
  echo "Syntax: $0 CTNAME"
  exit 1
fi 
CTNAME=$1
shift

#cd /etc/lxcutils/conf

if [ ! -f /etc/lxcutils/conf/${CTNAME}.conf ] ; then
  echo "FATAL: Could not find CT to restart, no /etc/lxcutils/conf/${CTNAME}.conf"
  exit 2
fi

echo "Calling lcu-stop $CTNAME"
lcu-stop $CTNAME || exit 11

echo "Sleeping a sec"
sleep 1

echo "Calling lcu-start $CTNAME"
lcu-start $CTNAME || exit 12

exit 0

