]> git.proxmox.com Git - pve-container.git/commitdiff
ct start: track lxc-start stderr and print in error case
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 9 Sep 2020 16:24:28 +0000 (18:24 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 9 Sep 2020 18:54:57 +0000 (20:54 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/LXC.pm
src/pve-container@.service

index e13f7e67697e559800ef4e010758875d1de9d442..f9aaaa915081118ba91d7603219fb342b6901aa3 100644 (file)
@@ -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"];
 
index d9185bca4c68105f49987f0171c1a71298e9b3ca..fdc373e0c20f26540d63db70d7d3398cec7aef35 100644 (file)
@@ -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