mirror of
https://github.com/fosrl/newt.git
synced 2026-03-05 10:16:44 +00:00
feat: checksocket protocol support
This commit is contained in:
@@ -83,18 +83,25 @@ func parseDockerHost(raw string) (dockerHost, error) {
|
|||||||
func CheckSocket(socketPath string) bool {
|
func CheckSocket(socketPath string) bool {
|
||||||
// Use the provided socket path or default to standard location
|
// Use the provided socket path or default to standard location
|
||||||
if socketPath == "" {
|
if socketPath == "" {
|
||||||
socketPath = "/var/run/docker.sock"
|
socketPath = "unix:///var/run/docker.sock"
|
||||||
}
|
}
|
||||||
|
host, err := parseDockerHost(socketPath)
|
||||||
// Try to create a connection to the Docker socket
|
|
||||||
conn, err := net.Dial("unix", socketPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Debug("Docker socket not available at %s: %v", socketPath, err)
|
logger.Debug("Invalid Docker socket path '%s': %v", socketPath, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
protocol := host.protocol
|
||||||
|
addr := host.address
|
||||||
|
|
||||||
|
// ssh might need different verification, but tcp works for basic reachability
|
||||||
|
conn, err := net.DialTimeout(protocol, addr, 2*time.Second)
|
||||||
|
if err != nil {
|
||||||
|
logger.Debug("Docker not reachable via %s at %s: %v", protocol, addr, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
logger.Debug("Docker socket is available at %s", socketPath)
|
logger.Debug("Docker reachable via %s at %s", protocol, addr)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user