]> git.proxmox.com Git - pve-container.git/blobdiff - src/lxc-pve-poststop-hook
update_lxc_config: remove ostype check
[pve-container.git] / src / lxc-pve-poststop-hook
index 8f19f63cfc54189bf4fe4af56a931f208292332e..0396739e1584c24af98c480e96c6af92325b71f7 100755 (executable)
@@ -49,14 +49,46 @@ __PACKAGE__->register_method ({
 
        my $vmid = $param->{name};
 
-       return undef if ! -f PVE::LXC::config_file($vmid);
+       return undef if ! -f PVE::LXC::Config->config_file($vmid);
        
-       my $conf = PVE::LXC::load_config($vmid);
+       my $conf = PVE::LXC::Config->load_config($vmid);
 
        my $storage_cfg = PVE::Storage::config();
 
         PVE::LXC::vm_stop_cleanup($storage_cfg, $vmid, $conf);
-       
+
+       my $rootfs = $ENV{LXC_ROOTFS_PATH};
+       die "Missing container root directory!\n" if !$rootfs;
+       PVE::Tools::run_command(['umount', '--recursive', $rootfs]);
+
+       # Because netlink is not a reliable protocol it can happen that lxc's
+       # link-deletion messages get lost (or end up being too early?)
+       for my $k (keys %$conf) {
+           next if $k !~ /^net(\d+)/;
+           my $ind = $1;
+           my $net = PVE::LXC::Config->parse_lxc_network($conf->{$k});
+           next if $net->{type} ne 'veth';
+           # veth_delete tests with '-d /sys/class/net/$name' before running the command
+           PVE::Network::veth_delete("veth${vmid}i$ind");
+       }
+
+       my $target = $ENV{LXC_TARGET};
+       if ($target && $target eq 'reboot') {
+           # In order to make sure hot-plugged config changes aren't reverted
+           # to what the monitor initially loaded we need to stop the container
+           # and restart it.
+           # Update the config and queue a restart of the lxc@$vmid task, note
+           # that we must not block because we're part of the service cgroup
+           # systemd waits for to die before issuing the new lxc-start command.
+           PVE::LXC::update_lxc_config($vmid, $conf);
+           # Tell the post-stop hook we want to be restarted.
+           open(my $fh, '>', "/var/lib/lxc/$vmid/reboot")
+               or die "failed to create reboot trigger file: $!\n";
+           close($fh);
+           # cause lxc to stop instead of rebooting
+           exit(1);
+       }
+
        return undef;
     }});