Selaa lähdekoodia

cmd/derpprobe: add -once flag for one-off CLI diagnostics

Updates #6478

Signed-off-by: James Tucker <[email protected]>
James Tucker 3 vuotta sitten
vanhempi
sitoutus
dc75b7cfd1
1 muutettua tiedostoa jossa 15 lisäystä ja 0 poistoa
  1. 15 0
      cmd/derpprobe/derpprobe.go

+ 15 - 0
cmd/derpprobe/derpprobe.go

@@ -35,6 +35,7 @@ import (
 var (
 	derpMapURL = flag.String("derp-map", "https://login.tailscale.com/derpmap/default", "URL to DERP map (https:// or file://)")
 	listen     = flag.String("listen", ":8030", "HTTP listen address")
+	probeOnce  = flag.Bool("once", false, "probe once and print results, then exit; ignores the listen flag")
 )
 
 // certReissueAfter is the time after which we expect all certs to be
@@ -63,6 +64,20 @@ func main() {
 	defer cancel()
 	_, _ = getDERPMap(ctx)
 
+	if *probeOnce {
+		log.Printf("Starting probe (may take up to 1m)")
+		probe()
+		log.Printf("Probe results:")
+		st := getOverallStatus()
+		for _, s := range st.good {
+			log.Printf("good: %s", s)
+		}
+		for _, s := range st.bad {
+			log.Printf("bad: %s", s)
+		}
+		return
+	}
+
 	go probeLoop()
 	go slackLoop()
 	log.Fatal(http.ListenAndServe(*listen, http.HandlerFunc(serve)))