From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC container] Improve feedback for startup
Date: Wed, 19 Aug 2020 12:30:37 +0200 [thread overview]
Message-ID: <20200819103037.15143-1-f.ebner@proxmox.com> (raw)
Since it was necessary to switch to 'Type=Simple' in the systemd
service (see 545d6f0a13ac2bf3a8d3f224c19c0e0def12116d ),
'systemctl start pve-container@ID' would not wait for the 'lxc-start'
command anymore. Thus every container start was reported as a success
and the 'post-start' hook would trigger immediately after the
'systemctl start' command.
Use 'lxc-monitor' to get the necessary information and detect
startup failure and only run the 'post-start' hookscript after
the container is effectively running. If something goes wrong
with the monitor, fall back to the old behavior.
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
src/PVE/LXC.pm | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index db5b8ca..35dc54c 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -2191,10 +2191,44 @@ sub vm_start {
PVE::Storage::activate_volumes($storage_cfg, $vollist);
+ my $monitor_pid = open(my $monitor_fh, '-|', "/usr/bin/lxc-monitor -n $vmid")
+ or warn "could not open pipe to lxc-monitor\n";
+
my $cmd = ['systemctl', 'start', "pve-container\@$vmid"];
PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'pre-start', 1);
- eval { PVE::Tools::run_command($cmd); };
+ eval {
+ PVE::Tools::run_command($cmd);
+
+ my $success;
+ if ($monitor_pid) {
+ eval {
+ local $SIG{ALRM} = sub { die "got timeout\n" };
+ alarm(10); # 'STARTING' should appear quickly
+
+ while (my $line = <$monitor_fh>) {
+ if ($line =~ m/^'$vmid' changed state to \[([A-Z]*)\]$/) {
+ my $status = $1;
+ alarm(0);
+ $success = 1 if $status eq 'RUNNING';
+ $success = 0 if $status eq 'ABORTING'
+ || $status eq 'STOPPING'
+ || $status eq 'STOPPED';
+ if (defined($success)) {
+ kill('KILL', $monitor_pid);
+ waitpid($monitor_pid, 0);
+ }
+ } else {
+ die "unexpected output from lxc-monitor: $line\n";
+ }
+ }
+ };
+ warn "Problem with lxc-monitor: $@" if $@;
+ alarm(0);
+ }
+ die "'lxc-start' failed for container '$vmid'\n"
+ if defined($success) && !$success;
+ };
if (my $err = $@) {
unlink $skiplock_flag_fn;
die $err;
--
2.20.1
next reply other threads:[~2020-08-19 10:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-19 10:30 Fabian Ebner [this message]
2020-08-20 9:36 ` Thomas Lamprecht
2020-08-27 8:44 ` Wolfgang Bumiller
2020-09-07 16:32 ` Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200819103037.15143-1-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox