-
Notifications
You must be signed in to change notification settings - Fork 1
/
service-debug.go
72 lines (57 loc) · 1.33 KB
/
service-debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package debug
import (
"context"
"github.com/gin-gonic/gin"
)
type componentDebug struct {
component
connector SSHConnector
}
func (comp *componentDebug) startSSH(ctx context.Context) (result chan error, err error) {
tty, err := comp.GetTTY()
if err != nil {
return nil, err
}
pty, err := tty.CreatePTY()
if err != nil {
return nil, err
}
if nil == comp.connector {
comp.connector = new(sshConnector)
}
result, err = comp.connector.Run(ctx, "ssh://pi@192.168.0.61:2022", 8443, pty)
if err != nil {
return nil, err
}
comp.SetState("running")
return result, nil
}
func newServiceDebug(svcs *services, rgAPI *gin.RouterGroup) Service {
svc := newEmptyService(svcs, "mypi-debug")
comp := &componentDebug{}
comp.startFunc = comp.startSSH
comp.info.Name = "ssh"
comp.info.Service = svc.Name()
comp.info.Actions = []ActionInfo{
{Name: "restart"},
}
svc.AddComponent(comp)
err := comp.Start()
if err != nil {
comp.SetState("failed")
}
svcs.Subscribe("mypi-router/go/port", func(topic string, value any) {
comp.connector.SetLocalRouterPort(value.(int)) // nolint: errcheck
})
sshFS, err := comp.connector.GetHttpFS()
if err == nil {
rgAPI.StaticFS("fs/", sshFS)
}
ccNodejs := newComponent(svc, "web")
err = ccNodejs.Start()
if err != nil {
comp.SetState("failed")
}
svc.GetComponent("web")
return svc
}