()
| 29 | ) |
| 30 | |
| 31 | func main() { |
| 32 | const usage = ` |
| 33 | Usage: |
| 34 | codis-proxy [--ncpu=N [--max-ncpu=MAX]] [--config=CONF] [--log=FILE] [--log-level=LEVEL] [--host-admin=ADDR] [--host-proxy=ADDR] [--dashboard=ADDR|--zookeeper=ADDR [--zookeeper-auth=USR:PWD]|--etcd=ADDR [--etcd-auth=USR:PWD]|--filesystem=ROOT|--fillslots=FILE] [--ulimit=NLIMIT] [--pidfile=FILE] [--product_name=NAME] [--product_auth=AUTH] [--session_auth=AUTH] |
| 35 | codis-proxy --default-config |
| 36 | codis-proxy --version |
| 37 | |
| 38 | Options: |
| 39 | --ncpu=N set runtime.GOMAXPROCS to N, default is runtime.NumCPU(). |
| 40 | -c CONF, --config=CONF run with the specific configuration. |
| 41 | -l FILE, --log=FILE set path/name of daliy rotated log file. |
| 42 | --log-level=LEVEL set the log-level, should be INFO,WARN,DEBUG or ERROR, default is INFO. |
| 43 | --ulimit=NLIMIT run 'ulimit -n' to check the maximum number of open file descriptors. |
| 44 | ` |
| 45 | |
| 46 | d, err := docopt.Parse(usage, nil, true, "", false) |
| 47 | if err != nil { |
| 48 | log.PanicError(err, "parse arguments failed") |
| 49 | } |
| 50 | |
| 51 | switch { |
| 52 | |
| 53 | case d["--default-config"]: |
| 54 | fmt.Println(proxy.DefaultConfig) |
| 55 | return |
| 56 | |
| 57 | case d["--version"].(bool): |
| 58 | fmt.Println("version:", utils.Version) |
| 59 | fmt.Println("compile:", utils.Compile) |
| 60 | return |
| 61 | |
| 62 | } |
| 63 | |
| 64 | if s, ok := utils.Argument(d, "--log"); ok { |
| 65 | w, err := log.NewRollingFile(s, log.DailyRolling) |
| 66 | if err != nil { |
| 67 | log.PanicErrorf(err, "open log file %s failed", s) |
| 68 | } else { |
| 69 | log.StdLog = log.New(w, "") |
| 70 | } |
| 71 | } |
| 72 | log.SetLevel(log.LevelInfo) |
| 73 | |
| 74 | if s, ok := utils.Argument(d, "--log-level"); ok { |
| 75 | if !log.SetLevelString(s) { |
| 76 | log.Panicf("option --log-level = %s", s) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if n, ok := utils.ArgumentInteger(d, "--ulimit"); ok { |
| 81 | b, err := exec.Command("/bin/sh", "-c", "ulimit -n").Output() |
| 82 | if err != nil { |
| 83 | log.PanicErrorf(err, "run ulimit -n failed") |
| 84 | } |
| 85 | if v, err := strconv.Atoi(strings.TrimSpace(string(b))); err != nil || v < n { |
| 86 | log.PanicErrorf(err, "ulimit too small: %d, should be at least %d", v, n) |
| 87 | } |
| 88 | } |
nothing calls this directly
no test coverage detected