mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-23 19:05:37 +00:00
Merge pull request #237 from ijc25/diagnostics
Fixup diagnostics logging
This commit is contained in:
commit
480bcf1be2
@ -5,16 +5,18 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"log/syslog"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rneugeba/virtsock/go/vsock"
|
|
||||||
"github.com/rneugeba/virtsock/go/hvsock"
|
"github.com/rneugeba/virtsock/go/hvsock"
|
||||||
|
"github.com/rneugeba/virtsock/go/vsock"
|
||||||
)
|
)
|
||||||
|
|
||||||
func run(timeout time.Duration, w *tar.Writer, command string, args ...string) {
|
func run(timeout time.Duration, w *tar.Writer, command string, args ...string) {
|
||||||
@ -22,11 +24,11 @@ func run(timeout time.Duration, w *tar.Writer, command string, args ...string) {
|
|||||||
c := exec.Command(command, args...)
|
c := exec.Command(command, args...)
|
||||||
stdoutPipe, err := c.StdoutPipe()
|
stdoutPipe, err := c.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to create stdout pipe: %#v", err)
|
log.Fatalf("Failed to create stdout pipe: %s", err)
|
||||||
}
|
}
|
||||||
stderrPipe, err := c.StderrPipe()
|
stderrPipe, err := c.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to create stderr pipe: %#v", err)
|
log.Fatalf("Failed to create stderr pipe: %s", err)
|
||||||
}
|
}
|
||||||
var stdoutBuffer bytes.Buffer
|
var stdoutBuffer bytes.Buffer
|
||||||
var stderrBuffer bytes.Buffer
|
var stderrBuffer bytes.Buffer
|
||||||
@ -111,8 +113,8 @@ func capture(w *tar.Writer) {
|
|||||||
run(t, w, "/usr/bin/dig", "@8.8.8.8", "docker.com")
|
run(t, w, "/usr/bin/dig", "@8.8.8.8", "docker.com")
|
||||||
run(t, w, "/usr/bin/wget", "-O", "-", "http://www.docker.com/")
|
run(t, w, "/usr/bin/wget", "-O", "-", "http://www.docker.com/")
|
||||||
run(t, w, "/usr/bin/wget", "-O", "-", "http://104.239.220.248/") // a www.docker.com address
|
run(t, w, "/usr/bin/wget", "-O", "-", "http://104.239.220.248/") // a www.docker.com address
|
||||||
run(t, w, "/usr/bin/wget", "-O", "-", "http://216.58.213.68/") // a www.google.com address
|
run(t, w, "/usr/bin/wget", "-O", "-", "http://216.58.213.68/") // a www.google.com address
|
||||||
run(t, w, "/usr/bin/wget", "-O", "-", "http://91.198.174.192/") // a www.wikipedia.com address
|
run(t, w, "/usr/bin/wget", "-O", "-", "http://91.198.174.192/") // a www.wikipedia.com address
|
||||||
|
|
||||||
// Dump the database
|
// Dump the database
|
||||||
dbBase := "/Database/branch/master/ro"
|
dbBase := "/Database/branch/master/ro"
|
||||||
@ -125,24 +127,36 @@ func capture(w *tar.Writer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
syslog, err := syslog.New(syslog.LOG_INFO|syslog.LOG_DAEMON, "diagnostics")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("Failed to open syslog", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.SetOutput(syslog)
|
||||||
|
log.SetFlags(0)
|
||||||
|
|
||||||
listeners := make([]net.Listener, 0)
|
listeners := make([]net.Listener, 0)
|
||||||
|
|
||||||
ip, err := net.Listen("tcp", ":62374")
|
ip, err := net.Listen("tcp", ":62374")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to bind to TCP port 62374: %#v", err)
|
log.Printf("Failed to bind to TCP port 62374: %s", err)
|
||||||
} else {
|
} else {
|
||||||
listeners = append(listeners, ip)
|
listeners = append(listeners, ip)
|
||||||
}
|
}
|
||||||
vsock, err := vsock.Listen(uint(62374))
|
vsock, err := vsock.Listen(uint(62374))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to bind to vsock port 62374: %#v", err)
|
if errno, ok := err.(syscall.Errno); !ok || errno != syscall.EAFNOSUPPORT {
|
||||||
|
log.Printf("Failed to bind to vsock port 62374: %s", err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
listeners = append(listeners, vsock)
|
listeners = append(listeners, vsock)
|
||||||
}
|
}
|
||||||
svcid, _ := hvsock.GuidFromString("445BA2CB-E69B-4912-8B42-D7F494D007EA")
|
svcid, _ := hvsock.GuidFromString("445BA2CB-E69B-4912-8B42-D7F494D007EA")
|
||||||
hvsock, err := hvsock.Listen(hvsock.HypervAddr{VmId: hvsock.GUID_WILDCARD, ServiceId: svcid})
|
hvsock, err := hvsock.Listen(hvsock.HypervAddr{VmId: hvsock.GUID_WILDCARD, ServiceId: svcid})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to bind to hvsock port: %#v", err)
|
if errno, ok := err.(syscall.Errno); !ok || errno != syscall.EAFNOSUPPORT {
|
||||||
|
log.Printf("Failed to bind to hvsock port: %s", err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
listeners = append(listeners, hvsock)
|
listeners = append(listeners, hvsock)
|
||||||
}
|
}
|
||||||
@ -152,7 +166,7 @@ func main() {
|
|||||||
for {
|
for {
|
||||||
conn, err := l.Accept()
|
conn, err := l.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error accepting connection: %#v", err)
|
log.Printf("Error accepting connection: %s", err)
|
||||||
return // no more listening
|
return // no more listening
|
||||||
}
|
}
|
||||||
go func(conn net.Conn) {
|
go func(conn net.Conn) {
|
||||||
|
Loading…
Reference in New Issue
Block a user