]> git.proxmox.com Git - pve-container.git/commitdiff
don't let lxc handle container reboots directly
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 28 Jul 2016 14:23:19 +0000 (16:23 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 5 Aug 2016 08:51:41 +0000 (10:51 +0200)
LXC doesn't reload the configuration on reboot causing
hotplugged changes to not be persistent across
container-side reboots.
Instead, let the post-stop hook return false so that lxc
stops while starting up a new instance in the background
with the updated config.

src/lxc-pve-poststop-hook

index 20569b23f119859475d9a3fe3f7c6ff16c70ba6a..b8524cc85740e217ebf4d1337b4afe115c6defad 100755 (executable)
@@ -72,6 +72,27 @@ __PACKAGE__->register_method ({
            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
+           local $SIG{HUP} = 'IGNORE';
+           my $pid = fork();
+           die "fork failed during container reboot: $!\n" if !defined($pid);
+           if (!$pid) {
+               POSIX::setsid();
+               close STDIN;
+               close STDOUT;
+               close STDERR;
+               PVE::LXC::update_lxc_config($vmid, $conf);
+               exec {'lxc-start'} 'lxc-start', '-n', $vmid
+               or POSIX::_exit(-1);
+           }
+           # cause lxc to stop instead of rebooting
+           POSIX::_exit(1);
+       }
+
        return undef;
     }});