]> git.proxmox.com Git - pve-container.git/blobdiff - src/PVE/API2/LXC.pm
destroy: check if container is still running
[pve-container.git] / src / PVE / API2 / LXC.pm
index 1e49d890d9aacdebb42e313cd9b216bfce9a7c63..a4e80ec7ac4592f088ef4b6707dd52a9f0f00511 100644 (file)
@@ -493,11 +493,17 @@ __PACKAGE__->register_method({
        die "unable to remove CT $vmid - used in HA resources\n"
            if PVE::HA::Config::vm_is_ha_managed($vmid);
 
+       my $running_error_msg = "unable to destroy CT $vmid - container is running\n";
+
+       die $running_error_msg if PVE::LXC::check_running($vmid); # check early
+
        my $code = sub {
            # reload config after lock
            $conf = PVE::LXC::load_config($vmid);
            PVE::LXC::check_lock($conf);
 
+           die $running_error_msg if PVE::LXC::check_running($vmid);
+
            PVE::LXC::destroy_lxc_container($storage_cfg, $vmid, $conf);
            PVE::AccessControl::remove_vm_access($vmid);
            PVE::Firewall::remove_vmfw_conf($vmid);