4
# lxc: linux Container library
7
# Daniel Lezcano <daniel.lezcano@free.fr>
9
# This library is free software; you can redistribute it and/or
10
# modify it under the terms of the GNU Lesser General Public
11
# License as published by the Free Software Foundation; either
12
# version 2.1 of the License, or (at your option) any later version.
14
# This library is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
# Lesser General Public License for more details.
19
# You should have received a copy of the GNU Lesser General Public
20
# License along with this library; if not, write to the Free Software
21
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
# This script allows to set or remove the capabilities on the lxc tools.
25
# When the capabilities are set, a non root user can manage the containers.
29
echo "usage: $0 -n <name> [-f]"
30
echo " -f: if a container is running, stop it first. Default is to abort"
33
if [ "$(id -u)" != "0" ]; then
34
echo "This command has to be run as root"
43
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
73
if [ -z "$lxc_name" ]; then
74
echo "no container name specified"
79
if [ ! -d "$lxc_path/$lxc_name" ]; then
80
echo "'$lxc_name' does not exist"
84
# make sure the container isn't running
85
lxc-info -n $lxc_name 2>/dev/null | grep -q RUNNING
87
if [ $force -eq 1 ]; then
90
echo "Container $lxc_name is running, aborting the deletion."
95
# Deduce the type of rootfs
96
# If LVM partition, destroy it. If anything else, ignore it. We'll support
97
# deletion of others later.
98
rootdev=`grep lxc.rootfs $lxc_path/$lxc_name/config 2>/dev/null | sed -e 's/^[^/]*/\//'`
99
if [ ! -z "$rootdev" ]; then
100
if [ -b "$rootdev" -o -h "$rootdev" ]; then
101
lvdisplay $rootdev > /dev/null 2>&1
102
if [ $? -eq 0 ]; then
103
echo "removing backing store: $rootdev"
108
# recursively remove the container to remove old container configuration
109
rm -rf --preserve-root $lxc_path/$lxc_name