From f74b348b260c69d4b560a107b268f2e9027ba0cc Mon Sep 17 00:00:00 2001 From: Kyle Sanderson Date: Tue, 12 Jul 2022 12:05:29 -0700 Subject: [PATCH] feat(config): detect container runtime (#324) * feat(config): add container detection capabilities --- internal/config/config.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/config/config.go b/internal/config/config.go index 6194250..b8d7559 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -7,6 +7,7 @@ import ( "path" "path/filepath" "sync" + "strings" "github.com/autobrr/autobrr/internal/domain" "github.com/autobrr/autobrr/internal/logger" @@ -36,6 +37,15 @@ func writeConfig(configPath string, configFile string) error { return err } + host := "127.0.0.1" + if pd, _ := os.Open("/proc/1/cgroup"); pd != nil { + defer pd.Close() + b := make([]byte, 4096, 4096) + pd.Read(b) + if strings.Contains(string(b), "/docker") || strings.Contains(string(b), "/lxc") { + host = "0.0.0.0" + } + } defer f.Close() _, err = f.WriteString(`# config.toml @@ -44,7 +54,7 @@ func writeConfig(configPath string, configFile string) error { # # Default: "localhost" # -host = "127.0.0.1" +host = "` + host + `" # Port #