public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] applied: [PATCH container 1/5] ct start: track lxc-start stderr and print in error case
Date: Wed,  9 Sep 2020 21:12:19 +0200	[thread overview]
Message-ID: <20200909191223.4187564-1-t.lamprecht@proxmox.com> (raw)

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
 src/PVE/LXC.pm             | 15 +++++++++++++++
 src/pve-container@.service |  2 +-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index e13f7e6..f9aaaa9 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -2167,6 +2167,17 @@ sub userns_command {
     return [];
 }
 
+my sub print_ct_stderr_log {
+    my ($vmid) = @_;
+    my $log = eval { file_get_contents("/run/pve/ct-$vmid.stderr") };
+    return if !$log;
+
+    while ($log =~ /^\h*(lxc-start:?\s+$vmid:?\s*\S+\s*)?(.*?)\h*$/gm) {
+	my $line = $2;
+	print STDERR "$line\n";
+    }
+}
+
 my sub monitor_state_change($$) {
     my ($monitor_socket, $vmid) = @_;
     die "no monitor socket\n" if !defined($monitor_socket);
@@ -2201,6 +2212,7 @@ my sub monitor_start($$) {
     if (my $err = $@) {
 	warn "problem with monitor socket, but continuing anyway: $err\n";
     } elsif (!$success) {
+	print_ct_stderr_log($vmid);
 	die "startup for container '$vmid' failed\n";
     }
 }
@@ -2233,6 +2245,9 @@ sub vm_start {
     my $monitor_socket = eval { PVE::LXC::Monitor::get_monitor_socket() };
     warn $@ if $@;
 
+    unlink "/run/pve/ct-$vmid.stderr"; # systemd does not truncate log files
+
+    my $base_unit = $conf->{debug} ? 'pve-container-debug' : 'pve-container';
 
     my $cmd = ['systemctl', 'start', "pve-container\@$vmid"];
 
diff --git a/src/pve-container@.service b/src/pve-container@.service
index d9185bc..fdc373e 100644
--- a/src/pve-container@.service
+++ b/src/pve-container@.service
@@ -19,4 +19,4 @@ ExecStop=/usr/share/lxc/pve-container-stop-wrapper %i
 # Environment=CONSOLETYPE=serial
 # Prevent container init from putting all its output into the journal
 StandardOutput=null
-StandardError=null
+StandardError=file:/run/pve/ct-%i.stderr
-- 
2.20.1





             reply	other threads:[~2020-09-09 19:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-09 19:12 Thomas Lamprecht [this message]
2020-09-09 19:12 ` [pve-devel] applied: [PATCH container 2/5] implement debug start Thomas Lamprecht
2020-09-09 19:12 ` [pve-devel] applied: [PATCH container 3/5] protected_call: remove left-over rootdir/dev mkdir Thomas Lamprecht
2020-09-09 19:12 ` [pve-devel] applied: [PATCH container 4/5] alpine: setup net: pass whole config to parent method Thomas Lamprecht
2020-09-09 19:12 ` [pve-devel] applied: [PATCH container 5/5] setup: heuristically warn if the FS hosting /etc is not mounted 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=20200909191223.4187564-1-t.lamprecht@proxmox.com \
    --to=t.lamprecht@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal