]> git.proxmox.com Git - pve-container.git/commitdiff
use the lxc@ service file provded by lxc
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 2 Feb 2017 10:02:36 +0000 (11:02 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 2 Feb 2017 10:12:48 +0000 (11:12 +0100)
Until now the lxc-start process was sort of a danglign
process in the pvedaemon.service cgroup when a container was
started from the web UI causing long stalls when trying to
restart pvedaemon and potential container kills. (Mostly
problematic when issuing package upgrades).
We now start containers via the lxc@ service file giving
them their own service cgroup.

The downside is that we'll have to patch the lxc@ service
file in the lxc package to Type=forking without the -F
option otherwise all of the the containers' console outputs
will end up in the logs...

src/PVE/API2/LXC/Status.pm
src/PVE/VZDump/LXC.pm
src/lxc-pve-poststop-hook

index 8c389f726cefe4785fd3521c264a2f33ba8deaf0..a3d11f13c13055e5a972515a24f1c58499ea98e2 100644 (file)
@@ -178,7 +178,7 @@ __PACKAGE__->register_method({
 
                    local $ENV{PVE_SKIPLOCK}=1 if $skiplock;
 
-                   my $cmd = ['lxc-start', '-n', $vmid];
+                   my $cmd = ['systemctl', 'start', "lxc\@$vmid"];
 
                    run_command($cmd);
 
index 0d871a1cd921e44b12bcb8394532fbc6aacb5404..fafffc6b8bf01fda30fe00fa48376219b2877697 100644 (file)
@@ -260,7 +260,7 @@ sub stop_vm {
 sub start_vm {
     my ($self, $task, $vmid) = @_;
 
-    $self->cmd ("lxc-start -n $vmid");
+    $self->cmd(['systemctl', 'start', "lxc\@$vmid"]);
 }
 
 sub suspend_vm {
index b8524cc85740e217ebf4d1337b4afe115c6defad..a4302d6bbf13f3efc4cbd01c79d2032c9063d0d5 100755 (executable)
@@ -74,21 +74,14 @@ __PACKAGE__->register_method ({
 
        my $target = $ENV{LXC_TARGET};
        if ($target && $target eq 'reboot') {
-           # in order to make sure hot-plugged config changes aren't reverted
+           # 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);
-           }
+           # 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);
+           PVE::Tools::run_command(['systemctl', '--no-block', 'restart', "lxc\@$vmid"]);
            # cause lxc to stop instead of rebooting
            POSIX::_exit(1);
        }