feat(config): detect container runtime (#324)

* feat(config): add container detection capabilities
This commit is contained in:
Kyle Sanderson 2022-07-12 12:05:29 -07:00 committed by GitHub
parent aa94962dfd
commit f74b348b26
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
#