-
Notifications
You must be signed in to change notification settings - Fork 25
/
siberite.go
56 lines (45 loc) · 1.06 KB
/
siberite.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
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net"
"os"
"os/signal"
"runtime"
"strconv"
"syscall"
service "github.com/bogdanovich/siberite/service"
)
var (
dataDir = flag.String("data", "./data", "path to data directory")
hostAndPort = flag.String("listen", "0.0.0.0:22133", "ip and port to listen")
pidPath = flag.String("pid", "", "path to PID file to use")
versionFlag = flag.Bool("version", false, "prints current version")
)
func main() {
flag.Parse()
runtime.GOMAXPROCS(runtime.NumCPU())
service := service.New(*dataDir)
if *versionFlag {
fmt.Println(service.Version())
os.Exit(0)
}
// Write a PID file if its requested
if len(*pidPath) > 0 {
if err := ioutil.WriteFile(*pidPath, []byte(strconv.Itoa(os.Getpid())), 0644); err != nil {
log.Fatalln(err)
}
defer os.Remove(*pidPath)
}
laddr, err := net.ResolveTCPAddr("tcp", *hostAndPort)
if err != nil {
log.Fatalln(err)
}
go service.Serve(laddr)
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
log.Println(<-ch)
service.Stop()
}