]> git.proxmox.com Git - pmg-api.git/commitdiff
pmgbanner: don't die if getting addr fails but running in container
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 23 Apr 2020 19:27:52 +0000 (21:27 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 23 Apr 2020 19:28:45 +0000 (21:28 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/bin/pmgbanner

index 2e6b51e770d2915234ecfc0a5ff65f35a66543a3..051b4da3591deace356b79a0d3c3f0c56f2959ac 100755 (executable)
@@ -4,10 +4,26 @@ use strict;
 use warnings;
 
 use PVE::INotify;
+use PVE::Tools;
 use PMG::Cluster;
 
+sub detect_container {
+
+    my $ct;
+    if (-f '/run/systemd/container') {
+       $ct = PVE::Tools::file_read_firstline('/run/systemd/container');
+    }
+    return $ct;
+}
+
 my $nodename = PVE::INotify::nodename();
-my $localip = PMG::Cluster::remote_node_ip($nodename, 1);
+my $localip = eval { PMG::Cluster::remote_node_ip($nodename, 1) };
+if (my $err = $@) { # FIXME: HACK: cope better with managed CTs and DHCP
+    my $in_ct = detect_container();
+    die $err if !$in_ct;
+    warn "ignore failure to get local IP of $nodename, we're in a container ($in_ct)\n";
+    $localip = '<uknown>';
+}
 
 my $xline = '-' x 78;