diff options
author | Serge Hallyn <serge.hallyn@canonical.com> | 2012-01-23 12:59:14 -0600 |
---|---|---|
committer | Daniel Lezcano <daniel.lezcano@free.fr> | 2012-02-26 10:44:40 +0100 |
commit | 76e08ff8a09abd43994d120e415f43a2a1ef4d90 (patch) | |
tree | 37d3c3920d092d2dae92e7bb83701b2e8e726e3b /src | |
parent | Support nested cgroups (diff) | |
download | lxc-76e08ff8a09abd43994d120e415f43a2a1ef4d90.tar.gz lxc-76e08ff8a09abd43994d120e415f43a2a1ef4d90.tar.bz2 lxc-76e08ff8a09abd43994d120e415f43a2a1ef4d90.zip |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/lxc/lxc-destroy.in | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/src/lxc/lxc-destroy.in b/src/lxc/lxc-destroy.in index c662c1f..b0f2da5 100644 --- a/src/lxc/lxc-destroy.in +++ b/src/lxc/lxc-destroy.in @@ -26,7 +26,8 @@ # 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 @@ -34,10 +35,11 @@ if [ "$(id -u)" != "0" ]; then exit 1 fi -shortoptions='n:' +shortoptions='n:f' longoptions='name:' localstatedir=@LOCALSTATEDIR@ lxc_path=@LXCPATH@ +force=0 getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@") if [ $? != 0 ]; then @@ -54,6 +56,10 @@ while true; do lxc_name=$1 shift ;; + -f) + force=1 + shift + ;; --) shift break;; @@ -76,14 +82,28 @@ if [ ! -d "$lxc_path/$lxc_name" ]; then exit 1 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 # If LVM partition, destroy it. If anything else, ignore it. We'll support # deletion of others later. -rootdev=`grep lxc.rootfs $lxc_path/$lxc_name/config | awk -F= '{ print $2 '}` -if [ -b $rootdev -o -h $rootdev ]; then - lvdisplay $rootdev > /dev/null 2>&1 - if [ $? -eq 0 ]; then - lvremove $rootdev +rootdev=`grep lxc.rootfs $lxc_path/$lxc_name/config 2>/dev/null | sed -e 's/^[^/]*/\//'` +if [ ! -z "$rootdev" ]; then + if [ -b "$rootdev" -o -h "$rootdev" ]; then + lvdisplay $rootdev > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo "removing backing store: $rootdev" + lvremove -f $rootdev + fi fi fi # recursively remove the container to remove old container configuration |