-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (45 loc) · 1.22 KB
/
main.go
File metadata and controls
51 lines (45 loc) · 1.22 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
package main
import (
"flag"
"fmt"
"os"
"github.com/bitleak/kaproxy/server"
)
type options struct {
showVersion bool
cmd string
confFile string
pidFile string
}
func parseOptions() *options {
opts := new(options)
flag.BoolVar(&opts.showVersion, "v", false, "Show Version")
flag.StringVar(&opts.cmd, "k", "", "status|stop")
flag.StringVar(&opts.confFile, "c", "conf/kaproxy-default.toml", "conf file path")
flag.StringVar(&opts.pidFile, "p", "/var/run/kaproxy.pid", "pid file path")
flag.Parse()
return opts
}
func main() {
//use "github.com/pkg/profile" to debug
//defer profile.Start(profile.TraceProfile, profile.ProfilePath("/tmp/pprof"), profile.NoShutdownHook).Stop()
opts := parseOptions()
if opts.showVersion {
fmt.Printf("%s\ncommit %s\nbuilt on %s\n", server.Version, server.BuildCommit, server.BuildDate)
os.Exit(0)
}
if opts.cmd != "" {
err := server.HandleUserCmd(opts.cmd, opts.pidFile)
if err != nil {
fmt.Printf("Handle user command(%s) error, %s\n", opts.cmd, err)
} else {
fmt.Printf("Handle user command(%s) succ\n", opts.cmd)
}
os.Exit(0)
}
err := server.Start(opts.confFile, opts.pidFile)
if err != nil {
fmt.Printf("Server start error, %s\n", err)
os.Exit(1)
}
}