From 2e64f0578563a2424ccaee39427717e11783ee77 Mon Sep 17 00:00:00 2001 From: Alwin Antreich Date: Wed, 14 Mar 2018 13:51:55 +0100 Subject: [PATCH] Fix pct skiplock The method vm_start sets an environment variable that is not picked up anymore by systemd. This patch removes the environment variable and introduces a skiplock file that is picked up by the lxc-pve-prestart-hook. Signed-off-by: Alwin Antreich --- src/PVE/LXC.pm | 13 +++++++++++-- src/lxc-pve-prestart-hook | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 7adbcd1..bec47dd 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -1545,11 +1545,20 @@ sub vm_start { update_lxc_config($vmid, $conf); - local $ENV{PVE_SKIPLOCK}=1 if $skiplock; + my $skiplock_flag_fn = "/run/lxc/skiplock-$vmid"; + + if ($skiplock) { + open(my $fh, '>', $skiplock_flag_fn) || die "failed to open $skiplock_flag_fn for writing: $!\n"; + close($fh); + } my $cmd = ['systemctl', 'start', "pve-container\@$vmid"]; - PVE::Tools::run_command($cmd); + eval { PVE::Tools::run_command($cmd); }; + if (my $err = $@) { + unlink $skiplock_flag_fn; + die $err if $err; + } return; } diff --git a/src/lxc-pve-prestart-hook b/src/lxc-pve-prestart-hook index fd29423..61a8ef3 100755 --- a/src/lxc-pve-prestart-hook +++ b/src/lxc-pve-prestart-hook @@ -57,13 +57,16 @@ __PACKAGE__->register_method ({ return undef if $param->{name} !~ m/^\d+$/; my $vmid = $param->{name}; + my $skiplock_flag_fn = "/run/lxc/skiplock-$vmid"; + my $skiplock = 1 if -e $skiplock_flag_fn; + unlink $skiplock_flag_fn if $skiplock; PVE::Cluster::check_cfs_quorum(); # only start if we have quorum return undef if ! -f PVE::LXC::Config->config_file($vmid); my $conf = PVE::LXC::Config->load_config($vmid); - if (!$ENV{PVE_SKIPLOCK} && !PVE::LXC::Config->has_lock($conf, 'mounted')) { + if (!$skiplock && !PVE::LXC::Config->has_lock($conf, 'mounted')) { PVE::LXC::Config->check_lock($conf); } -- 2.39.2