-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathmain.go
More file actions
71 lines (60 loc) · 1.93 KB
/
main.go
File metadata and controls
71 lines (60 loc) · 1.93 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
63
64
65
66
67
68
69
70
71
package main
import (
"os"
"sync"
"syscall"
"time"
_ "go.uber.org/automaxprocs"
"github.com/rudderlabs/rudder-go-kit/config"
kitctx "github.com/rudderlabs/rudder-go-kit/context"
"github.com/rudderlabs/rudder-go-kit/logger"
"github.com/rudderlabs/rudder-go-kit/mem"
"github.com/rudderlabs/rudder-server/runner"
)
var (
version = "Not an official release. Get the latest release from the github repo."
commit, buildDate, builtBy, enterpriseToken string
)
func main() {
c := config.Default
log := logger.NewLogger().Child("main")
ctx, shutdownFn := kitctx.NotifyContextWithCallback(func() {
log.Infon("Server received termination signal...")
}, syscall.SIGINT, syscall.SIGTERM)
log.Infon("Server is starting up...")
start := time.Now()
var wg sync.WaitGroup
mem.WatchMemoryLimit(ctx, &wg,
mem.WatchWithLogger(log),
mem.WatchWithPercentageLoader(c.GetReloadableIntVar(90, 1, "memoryLimitPercentage")),
)
shutdownOnNonReloadableConfigChange := c.GetReloadableBoolVar(false, "shutdownOnNonReloadableConfigChange")
c.OnNonReloadableConfigChange(func(key string) {
switch key {
case "statsExcludedTags": // keys to ignore
// no-op
default:
if shutdownOnNonReloadableConfigChange.Load() {
log.Infon("Config change detected, shutting down server...", logger.NewStringField("key", key))
shutdownFn()
} else {
log.Infon("Config change detected, but server will not shut down", logger.NewStringField("key", key))
}
}
})
r := runner.New(runner.ReleaseInfo{
Version: version,
Commit: commit,
BuildDate: buildDate,
BuiltBy: builtBy,
EnterpriseToken: config.GetString("ENTERPRISE_TOKEN", enterpriseToken),
})
exitCode := r.Run(ctx, shutdownFn, os.Args)
log.Infon("Server was shut down",
logger.NewIntField("exitCode", int64(exitCode)),
logger.NewDurationField("uptime", time.Since(start)),
)
shutdownFn()
wg.Wait()
os.Exit(exitCode)
}