From 8abb04afde0649412425a013064ec212a1aac460 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Wed, 6 Apr 2022 10:27:28 +0800 Subject: [PATCH] use hostname+pid instead of ip --- src/server/config/config.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/server/config/config.go b/src/server/config/config.go index c432774a..bed8c428 100644 --- a/src/server/config/config.go +++ b/src/server/config/config.go @@ -68,12 +68,21 @@ func MustLoad(fpaths ...string) { if C.Heartbeat.IP == "" { // auto detect - C.Heartbeat.IP = fmt.Sprint(GetOutboundIP()) + // C.Heartbeat.IP = fmt.Sprint(GetOutboundIP()) + // 自动获取IP在有些环境下容易出错,这里用hostname+pid来作唯一标识 - if C.Heartbeat.IP == "" { - fmt.Println("heartbeat ip auto got is blank") + hostname, err := os.Hostname() + if err != nil { + fmt.Println("failed to get hostname:", err) os.Exit(1) } + + C.Heartbeat.IP = hostname + "+" + fmt.Sprint(os.Getpid()) + + // if C.Heartbeat.IP == "" { + // fmt.Println("heartbeat ip auto got is blank") + // os.Exit(1) + // } } C.Heartbeat.Endpoint = fmt.Sprintf("%s:%d", C.Heartbeat.IP, C.HTTP.Port)