-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
101 lines (83 loc) · 2.26 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"os/signal"
_ "github.com/dmportella/docker-beat/builtin"
"github.com/dmportella/docker-beat/logging"
)
// Set on build
var (
Build string
Branch string
Revision string
OSArch string
)
// Variables used for command line parameters
var (
DockerEndpoint string
Consumer string
IndentJSON bool
Version bool
Verbose bool
Help bool
)
func init() {
const (
defaultDockerEndpoint = "unix:///var/run/docker.sock"
dockerEndpointUsage = "The Url or unix socket address for the Docker Remote API."
defaultConsumer = "console"
ConsumerUsage = "Consumer to use: Webhook, Rabbitmq, etc."
defaultIndentJSON = false
indentJSONUsage = "Indent the json output."
)
const (
defaultHelp = false
helpUsage = "Prints the help information."
defaultVerbose = false
verboseUsage = "Redirect trace information to the standard out."
)
flag.StringVar(&DockerEndpoint, "docker-endpoint", defaultDockerEndpoint, dockerEndpointUsage)
flag.StringVar(&Consumer, "consumer", defaultConsumer, ConsumerUsage)
flag.BoolVar(&IndentJSON, "indent", defaultIndentJSON, indentJSONUsage)
flag.BoolVar(&Verbose, "verbose", defaultVerbose, verboseUsage)
flag.BoolVar(&Help, "help", defaultHelp, helpUsage)
flag.Parse()
flag.Usage = func() {
fmt.Printf("Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
}
fmt.Printf("docker-beat - Version: %s Branch: %s Revision: %s. OSArch: %s.\n\rDaniel Portella (c) 2016\n\r", Build, Branch, Revision, OSArch)
if Verbose {
logging.Init(os.Stdout, os.Stdout, os.Stdout, os.Stderr)
} else {
logging.Init(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr)
}
if Help {
flag.Usage()
os.Exit(1)
}
}
func main() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for sig := range c {
if sig.String() == "interrupt" {
logging.Info.Printf("Application ended on %s\n\r", sig)
os.Exit(0)
}
}
}()
config := configuration{DockerEndpoint: DockerEndpoint, Consumer: Consumer, IndentJSON: IndentJSON}
beat, err := newDockerBeat(config)
if err == nil {
beat.Start()
} else {
panic(err)
}
// Simple way to keep program running until CTRL-C is pressed.
<-make(chan struct{})
}