forked from docker-archive/classicswarm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.go
78 lines (63 loc) · 1.65 KB
/
cli.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 cli
import (
"os"
"path"
"runtime/debug"
log "github.com/Sirupsen/logrus"
"github.com/docker/swarm/experimental"
"github.com/docker/swarm/version"
"github.com/urfave/cli"
)
// Run the Swarm CLI.
func Run() {
setProgramLimits()
app := cli.NewApp()
app.Name = path.Base(os.Args[0])
app.Usage = "A Docker-native clustering system"
app.Version = version.VERSION + " (" + version.GITCOMMIT + ")"
app.Author = ""
app.Email = ""
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
Usage: "debug mode",
EnvVar: "DEBUG",
},
cli.StringFlag{
Name: "log-level, l",
Value: "info",
Usage: "Log level (options: debug, info, warn, error, fatal, panic)",
},
cli.BoolFlag{
Name: "experimental",
Usage: "enable experimental features",
},
}
// logs
app.Before = func(c *cli.Context) error {
log.SetOutput(os.Stdout)
level, err := log.ParseLevel(c.String("log-level"))
if err != nil {
log.Fatal(err.Error())
}
log.SetLevel(level)
// If a log level wasn't specified and we are running in debug mode,
// enforce log-level=debug.
if !c.IsSet("log-level") && !c.IsSet("l") && c.Bool("debug") {
log.SetLevel(log.DebugLevel)
}
experimental.ENABLED = c.Bool("experimental")
return nil
}
app.Commands = commands
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func setProgramLimits() {
// Swarm runnable threads could be large when the number of nodes is large
// or under request bursts. Most threads are occupied by network connections.
// Increase max thread count from 10k default to 50k to accommodate it.
const maxThreadCount int = 50 * 1000
debug.SetMaxThreads(maxThreadCount)
}