]>
git.proxmox.com Git - pve-container.git/blob - src/lxc-pve-poststop-hook
17 PVE
::LXC
::Tools
::lxc_hook
('post-stop', 'lxc', sub {
18 my ($vmid, $vars, undef, undef) = @_;
20 return undef if ! -f PVE
::LXC
::Config-
>config_file($vmid);
22 my $conf = PVE
::LXC
::Config-
>load_config($vmid);
24 my $storage_cfg = PVE
::Storage
::config
();
26 PVE
::LXC
::vm_stop_cleanup
($storage_cfg, $vmid, $conf);
28 PVE
::Tools
::run_command
(['umount', '--recursive', $vars->{ROOTFS_PATH
}]);
30 # Because netlink is not a reliable protocol it can happen that lxc's
31 # link-deletion messages get lost (or end up being too early?)
32 for my $k (keys %$conf) {
33 next if $k !~ /^net(\d+)/;
35 my $net = PVE
::LXC
::Config-
>parse_lxc_network($conf->{$k});
36 next if $net->{type
} ne 'veth';
37 # veth_delete tests with '-d /sys/class/net/$name' before running the command
38 PVE
::Network
::veth_delete
("veth${vmid}i$ind");
41 my $config_updated = 0;
42 if ($conf->{pending
}) {
43 PVE
::LXC
::Config-
>vmconfig_apply_pending($vmid, $conf, $storage_cfg);
44 PVE
::LXC
::update_lxc_config
($vmid, $conf);
49 my $target = $vars->{TARGET
};
50 if ($target && $target eq 'reboot') {
51 # In order to make sure hot-plugged config changes aren't reverted
52 # to what the monitor initially loaded we need to stop the container
54 # Update the config and queue a restart of the pve-container@$vmid
55 # task, note that we must not block because we're part of the
56 # service cgroup systemd waits for to die before issuing the new
58 PVE
::LXC
::update_lxc_config
($vmid, $conf) if !$config_updated;
59 # Tell the post-stop hook we want to be restarted.
60 open(my $fh, '>', "/var/lib/lxc/$vmid/reboot")
61 or die "failed to create reboot trigger file: $!\n";
63 # cause lxc to stop instead of rebooting
67 PVE
::GuestHelpers
::exec_hookscript
($conf, $vmid, 'post-stop');