-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsidecar.go
More file actions
62 lines (53 loc) · 1.24 KB
/
sidecar.go
File metadata and controls
62 lines (53 loc) · 1.24 KB
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
package main
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"
"github.com/urfave/cli/v3"
"github.com/openUC2/device-admin/internal/app/sidecar"
)
var sidecarCmd = &cli.Command{
Name: "sidecar",
Action: sidecarMain,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "address",
Value: "tcp:127.0.0.1:2312",
Usage: "address of varlink service",
Sources: cli.EnvVars("SIDECAR_ADDRESS"),
},
},
}
var config = sidecar.Config{
Vendor: "OpenUC2",
Product: "device-admin sidecar",
URL: "https://github.com/openUC2/device-admin",
}
func sidecarMain(ctx context.Context, cmd *cli.Command) error {
e := echo.New() // TODO: get rid of this by using a more standard logging interface
e.Logger.SetLevel(log.INFO)
// Prepare sidecar
config.Version = toolVersion
config.Address = cmd.String("address")
s, err := sidecar.New(config, e.Logger)
if err != nil {
return err
}
// Run sidecar
ctxRun, cancelRun := signal.NotifyContext(
ctx, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT,
)
go func() {
if err = s.Run(ctxRun); err != nil {
e.Logger.Error(err.Error())
}
cancelRun()
}()
<-ctxRun.Done()
cancelRun()
e.Logger.Info("finished shutdown")
return nil
}