2023-03-24 13:04:29 +00:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
2024-01-03 20:23:07 +00:00
|
|
|
|
2024-05-05 11:03:50 +00:00
|
|
|
"github.com/thegeeklab/wp-plugin-go/v2/trace"
|
2023-03-24 13:04:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (p Plugin) startCoredns() {
|
|
|
|
cmd := exec.Command("coredns", "-conf", "/etc/coredns/Corefile")
|
2023-08-13 20:08:53 +00:00
|
|
|
if p.Settings.Daemon.Debug {
|
2023-03-24 13:04:29 +00:00
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
} else {
|
|
|
|
cmd.Stdout = io.Discard
|
|
|
|
cmd.Stderr = io.Discard
|
|
|
|
}
|
|
|
|
|
|
|
|
go func() {
|
2024-01-03 20:23:07 +00:00
|
|
|
trace.Cmd(cmd)
|
2023-03-24 13:04:29 +00:00
|
|
|
_ = cmd.Run()
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
func getContainerIP() (string, error) {
|
|
|
|
netInterfaceAddrList, err := net.InterfaceAddrs()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, netInterfaceAddr := range netInterfaceAddrList {
|
|
|
|
netIP, ok := netInterfaceAddr.(*net.IPNet)
|
|
|
|
if ok && !netIP.IP.IsLoopback() && netIP.IP.To4() != nil {
|
|
|
|
return netIP.IP.String(), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", nil
|
|
|
|
}
|