]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-destroy container only if it is in the STOPPED state
authorDwight Engen <dwight.engen@oracle.com>
Tue, 18 Dec 2012 21:12:34 +0000 (16:12 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Wed, 19 Dec 2012 16:07:50 +0000 (17:07 +0100)
Currently, lxc-destory will attempt to destroy a container if it is not in
the RUNNING state, but doing so is not good when the container is FROZEN, or
in other transitional states.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxc-destroy.in

index c72f18a33b23fac1ec413eda93b168e20db3facf..15274957487d0135a0c8ea8a10f9f3bc8bafbaf0 100644 (file)
@@ -94,14 +94,14 @@ 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
+# make sure the container is stopped
+state=`lxc-info -n $lxc_name 2>/dev/null | head -1 |awk '{print $2}'`
+if [ $state != "STOPPED" ]; then
     if [ $force -eq 1 ]; then
         lxc-stop -n $lxc_name
         lxc-wait -n $lxc_name -s STOPPED
     else
-        echo "$(basename $0): '$lxc_name' is running; aborted" >&2
+        echo "$(basename $0): '$lxc_name' is $state; aborted" >&2
         exit 1
     fi
 fi