status: print module info details
fixes https://github.com/gokrazy/gokrazy/issues/59
This commit is contained in:
parent
32f88999da
commit
b93a58e5c8
@ -25,6 +25,9 @@
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h3>module info</h3>
|
||||
<pre>{{ .Service.ModuleInfo }}</pre>
|
||||
|
||||
<h3>stdout</h3>
|
||||
<pre>
|
||||
{{ range $idx, $line := .Service.Stdout.Lines -}}
|
||||
|
1
go.mod
1
go.mod
@ -12,4 +12,5 @@ require (
|
||||
github.com/stretchr/testify v1.5.1 // indirect
|
||||
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413
|
||||
golang.org/x/sys v0.0.0-20200406155108-e3b113bbe6a4
|
||||
rsc.io/goversion v1.2.0
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@ -35,3 +35,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
rsc.io/goversion v1.2.0 h1:SPn+NLTiAG7w30IRK/DKp1BjvpWabYgxlLp/+kx5J8w=
|
||||
rsc.io/goversion v1.2.0/go.mod h1:Eih9y/uIBS3ulggl7KNJ09xGSLcuNaLgmvvqa07sgfo=
|
||||
|
File diff suppressed because one or more lines are too long
18
status.go
18
status.go
@ -17,6 +17,7 @@ import (
|
||||
|
||||
"github.com/gokrazy/gokrazy/internal/bundled"
|
||||
"github.com/gokrazy/internal/rootdev"
|
||||
"rsc.io/goversion/version"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@ -123,6 +124,23 @@ func model() string {
|
||||
return strings.TrimSpace(model)
|
||||
}
|
||||
|
||||
func readModuleInfo(path string) (string, error) {
|
||||
v, err := version.ReadExe(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
lines := strings.Split(strings.TrimSpace(v.ModuleInfo), "\n")
|
||||
shortened := make([]string, len(lines))
|
||||
for idx, line := range lines {
|
||||
row := strings.Split(line, "\t")
|
||||
if len(row) > 3 {
|
||||
row = row[:3]
|
||||
}
|
||||
shortened[idx] = strings.Join(row, "\t")
|
||||
}
|
||||
return strings.Join(shortened, "\n"), nil
|
||||
}
|
||||
|
||||
func initStatus(services []*service) {
|
||||
model := model()
|
||||
|
||||
|
10
supervise.go
10
supervise.go
@ -129,6 +129,10 @@ type lineswriter interface {
|
||||
}
|
||||
|
||||
type service struct {
|
||||
// config (never updated)
|
||||
ModuleInfo string
|
||||
|
||||
// state
|
||||
stopped bool
|
||||
stoppedMu sync.RWMutex
|
||||
cmd *exec.Cmd
|
||||
@ -258,6 +262,12 @@ func isDontSupervise(err error) bool {
|
||||
|
||||
func supervise(s *service) {
|
||||
tag := filepath.Base(s.cmd.Path)
|
||||
if modInfo, err := readModuleInfo(s.cmd.Path); err == nil {
|
||||
s.ModuleInfo = modInfo
|
||||
} else {
|
||||
log.Printf("cannot read module info from %s: %v", s.cmd.Path, err)
|
||||
}
|
||||
|
||||
s.Stdout = newLogWriter(tag)
|
||||
s.Stderr = newLogWriter(tag)
|
||||
l := log.New(s.Stderr, "", log.LstdFlags|log.Ldate|log.Ltime)
|
||||
|
Loading…
x
Reference in New Issue
Block a user