-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
command.go
100 lines (89 loc) · 3.13 KB
/
command.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
// Package run implements 'updater run'.
package run
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/spf13/cobra"
"go.uber.org/fx"
"github.com/DataDog/datadog-agent/cmd/updater/command"
"github.com/DataDog/datadog-agent/comp/core"
"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/comp/core/log/logimpl"
"github.com/DataDog/datadog-agent/comp/core/pid"
"github.com/DataDog/datadog-agent/comp/core/pid/pidimpl"
"github.com/DataDog/datadog-agent/comp/core/secrets"
"github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl"
"github.com/DataDog/datadog-agent/comp/remote-config/rcservice"
"github.com/DataDog/datadog-agent/comp/remote-config/rcservice/rcserviceimpl"
"github.com/DataDog/datadog-agent/comp/remote-config/rctelemetryreporter/rctelemetryreporterimpl"
"github.com/DataDog/datadog-agent/pkg/config/remote/service"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/DataDog/datadog-agent/comp/updater/localapi"
"github.com/DataDog/datadog-agent/comp/updater/localapi/localapiimpl"
"github.com/DataDog/datadog-agent/comp/updater/updater/updaterimpl"
pkgconfig "github.com/DataDog/datadog-agent/pkg/config"
)
type cliParams struct {
command.GlobalParams
}
// Commands returns the run command
func Commands(global *command.GlobalParams) []*cobra.Command {
runCmd := &cobra.Command{
Use: "run",
Short: "Runs the updater",
Long: ``,
RunE: func(cmd *cobra.Command, args []string) error {
return runFxWrapper(&cliParams{
GlobalParams: *global,
})
},
}
return []*cobra.Command{runCmd}
}
func runFxWrapper(params *cliParams) error {
ctx := context.Background()
return fxutil.OneShot(
run,
fx.Provide(func() context.Context { return ctx }),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(params.GlobalParams.ConfFilePath),
SecretParams: secrets.NewEnabledParams(),
SysprobeConfigParams: sysprobeconfigimpl.NewParams(),
LogParams: logimpl.ForDaemon("UPDATER", "updater.log_file", pkgconfig.DefaultUpdaterLogFile),
}),
core.Bundle(),
fx.Supply(&rcservice.Params{
Options: []service.Option{
service.WithDatabaseFileName("remote-config-updater.db"),
},
}),
rctelemetryreporterimpl.Module(),
rcserviceimpl.Module(),
updaterimpl.Module(),
localapiimpl.Module(),
fx.Supply(pidimpl.NewParams(params.PIDFilePath)),
)
}
func run(shutdowner fx.Shutdowner, _ pid.Component, _ localapi.Component) error {
handleSignals(shutdowner)
return nil
}
func handleSignals(shutdowner fx.Shutdowner) {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGPIPE)
for signo := range sigChan {
switch signo {
case syscall.SIGINT, syscall.SIGTERM:
log.Infof("Received signal %d (%v)", signo, signo)
_ = shutdowner.Shutdown()
return
}
}
}