From: Thomas Lamprecht Date: Thu, 23 Apr 2020 19:27:52 +0000 (+0200) Subject: pmgbanner: don't die if getting addr fails but running in container X-Git-Url: https://git.proxmox.com/?p=pmg-api.git;a=commitdiff_plain;h=b468a858b99c49229dd3d54944a455ff6ddda55d pmgbanner: don't die if getting addr fails but running in container Signed-off-by: Thomas Lamprecht --- diff --git a/src/bin/pmgbanner b/src/bin/pmgbanner index 2e6b51e..051b4da 100755 --- a/src/bin/pmgbanner +++ b/src/bin/pmgbanner @@ -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 = ''; +} my $xline = '-' x 78;