-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (44 loc) · 1.09 KB
/
main.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
package main
import (
"flag"
"os"
"os/signal"
"path/filepath"
"syscall"
"github.com/AlverLyu/dna-ipfs/conf"
"github.com/AlverLyu/dna-ipfs/ipfs"
"github.com/AlverLyu/dna-ipfs/jsonrpc"
)
var CfgFile string
var LogFile string
func main() {
binPath, err := os.Executable()
if err != nil {
binPath = "."
}
binDir := filepath.Dir(binPath)
flag.StringVar(&CfgFile, "c", binDir+"/dnaipfs.cfg", "The path of config file")
flag.StringVar(&LogFile, "lc", "", "The path of log config file")
flag.Parse()
if len(LogFile) > 0 {
conf.OpenCustomLog(LogFile)
} else {
os.Mkdir(binDir+"/log", os.ModePerm)
conf.OpenDefaultLog(binDir + "/log/dnaipfs.log")
}
conf.GCfg.Init(CfgFile)
ipfs.SetIPFSURL(conf.GCfg.IPFSURL)
rpcServer := jsonrpc.NewJsonRpcServer(conf.GCfg.Port, conf.GCfg.RpcPath, conf.GCfg.ReadTimeout, conf.GCfg.WriteTimeout, conf.GCfg.MaxHeaderBytes)
rpcServer.Start()
waitToExit()
}
func waitToExit() {
exit := make(chan bool, 0)
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
go func() {
<-sc
close(exit)
}()
<-exit
}