forked from rancher/container-crontab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
75 lines (65 loc) · 1.42 KB
/
Copy pathmain.go
File metadata and controls
75 lines (65 loc) · 1.42 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
72
73
74
75
package main
import (
"context"
"os"
"time"
"github.com/PastureStack/container-cron/events"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
// VERSION of the application
var (
MetadataURL = "http://169.254.169.250/2016-07-29"
VERSION = "v0.0.0-dev"
)
func beforeApp(c *cli.Context) error {
if c.GlobalBool("debug") {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
}
func main() {
app := cli.NewApp()
app.Name = "container-cron"
app.Version = VERSION
app.Usage = "Run scheduled actions against Docker containers"
app.Action = start
app.Before = beforeApp
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug,d",
},
cli.BoolFlag{
Name: "metadata-mode,m",
Usage: "Enable service-state checks through the metadata API",
},
cli.StringFlag{
Name: "metadata-url",
Value: MetadataURL,
Usage: "Provide full URL of Metadata",
},
cli.BoolFlag{
Name: "metrics",
},
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}
func start(c *cli.Context) error {
handler, err := events.NewDockerHandler(&events.DockerHandlerOpts{
MetadataMode: c.GlobalBool("metadata-mode"),
MetadataURL: c.GlobalString("metadata-url"),
})
if err != nil {
return err
}
router, err := events.NewEventRouter()
if err != nil {
return err
}
if c.GlobalBool("metrics") {
go MetricsServer(handler)
}
return events.StartRouter(context.Background(), router, handler, time.Second)
}