[pve-devel] [PATCH container 3/3] don't let lxc handle container reboots directly

Wolfgang Bumiller w.bumiller at proxmox.com
Thu Jul 28 16:23:19 CEST 2016


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.
---
LXD seems to be doing the same thing...

 src/lxc-pve-poststop-hook | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/lxc-pve-poststop-hook b/src/lxc-pve-poststop-hook
index 20569b2..b8524cc 100755
--- a/src/lxc-pve-poststop-hook
+++ b/src/lxc-pve-poststop-hook
@@ -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;
     }});
 
-- 
2.1.4





More information about the pve-devel mailing list