From b468a858b99c49229dd3d54944a455ff6ddda55d Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Thu, 23 Apr 2020 21:27:52 +0200 Subject: [PATCH] pmgbanner: don't die if getting addr fails but running in container Signed-off-by: Thomas Lamprecht --- src/bin/pmgbanner | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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; -- 2.39.2