]>
Commit | Line | Data |
---|---|---|
32e6d659 AD |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
4ed2b825 | 5 | |
32e6d659 AD |
6 | use POSIX; |
7 | use File::Path; | |
8 | ||
1a416433 | 9 | use PVE::GuestHelpers; |
0a49c44e WB |
10 | use PVE::LXC::Config; |
11 | use PVE::LXC::Tools; | |
12 | use PVE::LXC; | |
13 | use PVE::Network; | |
14 | use PVE::Storage; | |
15 | use PVE::Tools; | |
32e6d659 | 16 | |
0a49c44e WB |
17 | PVE::LXC::Tools::lxc_hook('post-stop', 'lxc', sub { |
18 | my ($vmid, $vars, undef, undef) = @_; | |
19 | ||
20 | return undef if ! -f PVE::LXC::Config->config_file($vmid); | |
21 | ||
22 | my $conf = PVE::LXC::Config->load_config($vmid); | |
23 | ||
24 | my $storage_cfg = PVE::Storage::config(); | |
25 | ||
0a49c44e WB |
26 | PVE::Tools::run_command(['umount', '--recursive', $vars->{ROOTFS_PATH}]); |
27 | ||
dc06f461 WB |
28 | PVE::LXC::vm_stop_cleanup($storage_cfg, $vmid, $conf); |
29 | ||
0a49c44e WB |
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+)/; | |
34 | my $ind = $1; | |
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"); | |
39 | } | |
40 | ||
1b54db95 OB |
41 | my $config_updated = 0; |
42 | if ($conf->{pending}) { | |
6a1cf3b9 TL |
43 | eval { PVE::LXC::Config->vmconfig_apply_pending($vmid, $conf, $storage_cfg) }; |
44 | warn "$@" if $@; | |
1b54db95 OB |
45 | PVE::LXC::update_lxc_config($vmid, $conf); |
46 | $config_updated = 1; | |
47 | } | |
48 | ||
49 | ||
0a49c44e WB |
50 | my $target = $vars->{TARGET}; |
51 | if ($target && $target eq 'reboot') { | |
52 | # In order to make sure hot-plugged config changes aren't reverted | |
53 | # to what the monitor initially loaded we need to stop the container | |
54 | # and restart it. | |
55 | # Update the config and queue a restart of the pve-container@$vmid | |
56 | # task, note that we must not block because we're part of the | |
57 | # service cgroup systemd waits for to die before issuing the new | |
58 | # lxc-start command. | |
1b54db95 | 59 | PVE::LXC::update_lxc_config($vmid, $conf) if !$config_updated; |
0a49c44e WB |
60 | # Tell the post-stop hook we want to be restarted. |
61 | open(my $fh, '>', "/var/lib/lxc/$vmid/reboot") | |
62 | or die "failed to create reboot trigger file: $!\n"; | |
63 | close($fh); | |
64 | # cause lxc to stop instead of rebooting | |
65 | exit(1); | |
66 | } | |
67 | ||
68 | PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-stop'); | |
69 | }); |