-
Notifications
You must be signed in to change notification settings - Fork 127
/
main.go
78 lines (65 loc) · 2.25 KB
/
main.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
package main
import (
"net/http"
"os"
"os/signal"
"syscall"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/armadaproject/armada/internal/common"
"github.com/armadaproject/armada/internal/common/armadacontext"
"github.com/armadaproject/armada/internal/common/health"
"github.com/armadaproject/armada/internal/common/logging"
"github.com/armadaproject/armada/internal/common/profiling"
"github.com/armadaproject/armada/internal/common/serve"
"github.com/armadaproject/armada/internal/executor"
"github.com/armadaproject/armada/internal/executor/configuration"
)
const CustomConfigLocation string = "config"
func init() {
pflag.StringSlice(
CustomConfigLocation,
[]string{},
"Fully qualified path to application configuration file (for multiple config files repeat this arg or separate paths with commas)",
)
pflag.Parse()
}
func main() {
common.ConfigureLogging()
common.BindCommandlineArguments()
var config configuration.ExecutorConfiguration
userSpecifiedConfigs := viper.GetStringSlice(CustomConfigLocation)
common.LoadConfig(&config, "./config/executor", userSpecifiedConfigs)
// Expose profiling endpoints if enabled.
if config.PprofPort != nil {
pprofServer := profiling.SetupPprofHttpServer(*config.PprofPort)
go func() {
ctx := armadacontext.Background()
if err := serve.ListenAndServe(ctx, pprofServer); err != nil {
logging.WithStacktrace(ctx, err).Error("pprof server failure")
}
}()
}
mux := http.NewServeMux()
startupCompleteCheck := health.NewStartupCompleteChecker()
healthChecks := health.NewMultiChecker(startupCompleteCheck)
health.SetupHttpMux(mux, healthChecks)
shutdownHttpServer := common.ServeHttp(config.HttpPort, mux)
defer shutdownHttpServer()
shutdownChannel := make(chan os.Signal, 1)
signal.Notify(shutdownChannel, syscall.SIGINT, syscall.SIGTERM)
shutdownMetricServer := common.ServeMetricsFor(
config.Metric.Port,
prometheus.Gatherers{prometheus.DefaultGatherer},
)
defer shutdownMetricServer()
shutdown, wg := executor.StartUp(armadacontext.Background(), logrus.NewEntry(logrus.New()), config)
go func() {
<-shutdownChannel
shutdown()
}()
startupCompleteCheck.MarkComplete()
wg.Wait()
}