From 238bbfa55e13bbd6369c70dfb7d625963ed294de Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 12 Jun 2018 22:22:47 +0200 Subject: [PATCH] init: update listeners when pressing on the serial console MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is useful when the network doesn’t come up correctly: you can connect a network cable between your computer and the gokrazy machine, press on the serial console and connect to gokrazy via its IPv6 link-local address (to find the address, use ping6 ff02::1%eth0). --- gokrazy.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gokrazy.go b/gokrazy.go index 1bb16b5..c41c6e4 100644 --- a/gokrazy.go +++ b/gokrazy.go @@ -8,6 +8,7 @@ package gokrazy import ( + "bufio" "fmt" "io/ioutil" "log" @@ -149,6 +150,18 @@ func Supervise(commands []*exec.Cmd) error { } }() + go func() { + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + if err := updateListeners("80"); err != nil { + log.Printf("updating listeners: %v", err) + } + } + if err := scanner.Err(); err != nil { + log.Print(err) + } + }() + return nil }