]> git.proxmox.com Git - pve-container.git/commitdiff
start: add pre-start-hook log-warn infra
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 5 Jul 2021 16:54:10 +0000 (18:54 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 5 Jul 2021 16:54:36 +0000 (18:54 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/LXC.pm
src/lxc-pve-prestart-hook

index 393da1b5e9ce923df538d0f4af8561e9e73cf7aa..3e80ddfa57a2332569a7ed0475b5b1c198337a57 100644 (file)
@@ -29,6 +29,7 @@ use PVE::Tools qw(
     $IPV4RE
     $IPV6RE
 );
+use PVE::RPCEnvironment;
 use PVE::CpuSet;
 use PVE::Network;
 use PVE::AccessControl;
@@ -2237,6 +2238,22 @@ my sub print_ct_stderr_log {
        print STDERR "$line\n";
     }
 }
+my sub print_ct_warn_log {
+    my ($vmid) = @_;
+    my $log_fn = "/run/pve/ct-$vmid.warnings";
+    my $log = eval { file_get_contents($log_fn) };
+    return if !$log;
+
+    my $rpcenv = eval { PVE::RPCEnvironment::get() };
+
+    my $warn_fn = $rpcenv ? sub { $rpcenv->warn($_[0]) } : sub { print STDERR "WARN: $_[0]\n" };
+
+    while ($log =~ /^\h*\s*(.*?)\h*$/gm) {
+       my $line = $1;
+       $warn_fn->($line);
+    }
+    unlink $log_fn or warn "could not unlink '$log_fn' - $!\n";
+}
 
 my sub monitor_state_change($$) {
     my ($monitor_socket, $vmid) = @_;
@@ -2320,6 +2337,8 @@ sub vm_start {
 
        # if debug is requested, print the log it also when the start succeeded
        print_ct_stderr_log($vmid) if $is_debug;
+
+       print_ct_warn_log($vmid); # always print warn log, if any
     };
     if (my $err = $@) {
        unlink $skiplock_flag_fn;
index fac587e996d417e39aa60525aa067cac8d37be28..f51b34cb33d44fc5b8a8b1710d0f12c4462bfb96 100755 (executable)
@@ -20,6 +20,16 @@ use PVE::Storage;
 use PVE::Syscall qw(:fsmount);
 use PVE::Tools qw(AT_FDCWD O_PATH);
 
+my $WARNFD;
+sub log_warn {
+    my ($vmid, $message) = @_;
+
+    if (!defined($WARNFD)) {
+       open($WARNFD, '>', "/run/pve/ct-${vmid}.warnings");
+    }
+    print $WARNFD "$message\n";
+}
+
 PVE::LXC::Tools::lxc_hook('pre-start', 'lxc', sub {
     my ($vmid, $vars, undef, undef) = @_;