mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-15 01:54:18 +00:00
Fix several nagging bugs in lxc-destroy
Don't delete a running container. If it's running, abort the delete unless a new '-f' (force) flag is given, in which case, stop it first. Handle the case where we can't find $rootfs in config Fix broken detection of lvm backing store Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com> Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
parent
d08ba6ec05
commit
76e08ff8a0
@ -26,7 +26,8 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: $0 -n <name>"
|
echo "usage: $0 -n <name> [-f]"
|
||||||
|
echo " -f: if a container is running, stop it first. Default is to abort"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$(id -u)" != "0" ]; then
|
if [ "$(id -u)" != "0" ]; then
|
||||||
@ -34,10 +35,11 @@ if [ "$(id -u)" != "0" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
shortoptions='n:'
|
shortoptions='n:f'
|
||||||
longoptions='name:'
|
longoptions='name:'
|
||||||
localstatedir=@LOCALSTATEDIR@
|
localstatedir=@LOCALSTATEDIR@
|
||||||
lxc_path=@LXCPATH@
|
lxc_path=@LXCPATH@
|
||||||
|
force=0
|
||||||
|
|
||||||
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
|
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
@ -54,6 +56,10 @@ while true; do
|
|||||||
lxc_name=$1
|
lxc_name=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-f)
|
||||||
|
force=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
break;;
|
break;;
|
||||||
@ -76,14 +82,28 @@ if [ ! -d "$lxc_path/$lxc_name" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# make sure the container isn't running
|
||||||
|
lxc-info -n $lxc_name 2>/dev/null | grep -q RUNNING
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
if [ $force -eq 1 ]; then
|
||||||
|
lxc-stop -n $lxc_name
|
||||||
|
else
|
||||||
|
echo "Container $lxc_name is running, aborting the deletion."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Deduce the type of rootfs
|
# Deduce the type of rootfs
|
||||||
# If LVM partition, destroy it. If anything else, ignore it. We'll support
|
# If LVM partition, destroy it. If anything else, ignore it. We'll support
|
||||||
# deletion of others later.
|
# deletion of others later.
|
||||||
rootdev=`grep lxc.rootfs $lxc_path/$lxc_name/config | awk -F= '{ print $2 '}`
|
rootdev=`grep lxc.rootfs $lxc_path/$lxc_name/config 2>/dev/null | sed -e 's/^[^/]*/\//'`
|
||||||
if [ -b $rootdev -o -h $rootdev ]; then
|
if [ ! -z "$rootdev" ]; then
|
||||||
|
if [ -b "$rootdev" -o -h "$rootdev" ]; then
|
||||||
lvdisplay $rootdev > /dev/null 2>&1
|
lvdisplay $rootdev > /dev/null 2>&1
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
lvremove $rootdev
|
echo "removing backing store: $rootdev"
|
||||||
|
lvremove -f $rootdev
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
# recursively remove the container to remove old container configuration
|
# recursively remove the container to remove old container configuration
|
||||||
|
Loading…
Reference in New Issue
Block a user