Commits

Audrius Kažukauskas committed c986db0

Check if container is running before removing it.

Comments (0)

Files changed (1)

usr/libexec/lxc-slack/rmc

     exit 1
   fi
 
+  # Check if container is running before removing it.
+  if lxc-info -n ${CONTAINER_NAME} | grep -q 'RUNNING' ; then
+    echo "Cannot destroy: container '$CONTAINER_NAME' is running." >&2
+    exit 1
+  fi
+
   lxc-destroy -n ${CONTAINER_NAME} || {
-    echo "Cannot destroy container $CONTAINER_NAME using lxc-destroy." >&2
+    echo "Cannot destroy container '$CONTAINER_NAME' using lxc-destroy." >&2
     exit 1
   }
 
   btrfs subvolume delete ${CONTAINER} || {
-    echo "Failed to delete subvolume." >&2
+    echo "Failed to delete $CONTAINER subvolume." >&2
     exit 1
   }
   rm -f ${CONTAINER}.{conf,fstab}