forked from ha/doozerd
/
doozerd.go
65 lines (51 loc) · 1.2 KB
/
doozerd.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
package main
import (
"doozer"
"doozer/util"
"flag"
"fmt"
"net"
"os"
)
var (
listenAddr = flag.String("l", "127.0.0.1:8046", "The address to bind to.")
attachAddr = flag.String("a", "", "The address of another node to attach to.")
webAddr = flag.String("w", ":8080", "Serve web requests on this address.")
clusterName = flag.String("c", "local", "The non-empty cluster name.")
showVersion = flag.Bool("v", false, "print doozerd's version string")
)
func Usage() {
fmt.Fprintf(os.Stderr, "Usage: %s [OPTIONS]\n", os.Args[0])
fmt.Fprintf(os.Stderr, "\nOptions:\n")
flag.PrintDefaults()
}
func main() {
util.LogWriter = os.Stderr
flag.Usage = Usage
flag.Parse()
if *showVersion {
fmt.Println("doozerd", doozer.Version)
return
}
if *listenAddr == "" {
fmt.Fprintln(os.Stderr, "require a listen address")
flag.Usage()
os.Exit(1)
}
listener, err := net.Listen("tcp", *listenAddr)
if err != nil {
panic(err)
}
conn, err := net.ListenPacket("udp", *listenAddr)
if err != nil {
panic(err)
}
var wl net.Listener
if *webAddr != "" {
wl, err = net.Listen("tcp", *webAddr)
if err != nil {
panic(err)
}
}
doozer.Main(*clusterName, *attachAddr, conn, listener, wl)
}