...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package main
17
18 import (
19 "flag"
20 "os"
21
22 "github.com/prometheus/client_golang/prometheus"
23 "github.com/prometheus/client_golang/prometheus/collectors"
24 ctrl "sigs.k8s.io/controller-runtime"
25 "sigs.k8s.io/controller-runtime/pkg/log/zap"
26
27 "github.com/chaos-mesh/chaos-mesh/pkg/chaosdaemon"
28 "github.com/chaos-mesh/chaos-mesh/pkg/fusedev"
29 "github.com/chaos-mesh/chaos-mesh/pkg/version"
30 )
31
32 var (
33 log = ctrl.Log.WithName("chaos-daemon")
34 conf = &chaosdaemon.Config{Host: "0.0.0.0"}
35
36 printVersion bool
37 )
38
39 func init() {
40 flag.BoolVar(&printVersion, "version", false, "print version information and exit")
41 flag.IntVar(&conf.GRPCPort, "grpc-port", 31767, "the port which grpc server listens on")
42 flag.IntVar(&conf.HTTPPort, "http-port", 31766, "the port which http server listens on")
43 flag.StringVar(&conf.Runtime, "runtime", "docker", "current container runtime")
44 flag.StringVar(&conf.CaCert, "ca", "", "ca certificate of grpc server")
45 flag.StringVar(&conf.Cert, "cert", "", "certificate of grpc server")
46 flag.StringVar(&conf.Key, "key", "", "key of grpc server")
47 flag.BoolVar(&conf.Profiling, "pprof", false, "enable pprof")
48
49 flag.Parse()
50 }
51
52 func main() {
53 version.PrintVersionInfo("Chaos-daemon")
54
55 if printVersion {
56 os.Exit(0)
57 }
58
59 ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
60
61 reg := prometheus.NewRegistry()
62 reg.MustRegister(
63
64 collectors.NewGoCollector(),
65 collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
66 )
67
68 log.Info("grant access to /dev/fuse")
69 err := fusedev.GrantAccess()
70 if err != nil {
71 log.Error(err, "fail to grant access to /dev/fuse")
72 }
73
74 if err = chaosdaemon.StartServer(conf, reg); err != nil {
75 log.Error(err, "failed to start chaos-daemon server")
76 os.Exit(1)
77 }
78 }
79