forked from ouqiang/gocron
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnode.go
76 lines (67 loc) · 1.94 KB
/
node.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
66
67
68
69
70
71
72
73
74
75
76
// Command gocron-node
package main
import (
"flag"
"os"
"runtime"
"strings"
"github.com/ouqiang/gocron/internal/modules/rpc/auth"
"github.com/ouqiang/gocron/internal/modules/rpc/server"
"github.com/ouqiang/gocron/internal/modules/utils"
"github.com/ouqiang/goutil"
log "github.com/sirupsen/logrus"
)
var (
AppVersion, BuildDate, GitCommit string
)
func main() {
var serverAddr string
var allowRoot bool
var version bool
var CAFile string
var certFile string
var keyFile string
var enableTLS bool
var logLevel string
flag.BoolVar(&allowRoot, "allow-root", false, "./gocron-node -allow-root")
flag.StringVar(&serverAddr, "s", "0.0.0.0:5921", "./gocron-node -s ip:port")
flag.BoolVar(&version, "v", false, "./gocron-node -v")
flag.BoolVar(&enableTLS, "enable-tls", false, "./gocron-node -enable-tls")
flag.StringVar(&CAFile, "ca-file", "", "./gocron-node -ca-file path")
flag.StringVar(&certFile, "cert-file", "", "./gocron-node -cert-file path")
flag.StringVar(&keyFile, "key-file", "", "./gocron-node -key-file path")
flag.StringVar(&logLevel, "log-level", "info", "-log-level error")
flag.Parse()
level, err := log.ParseLevel(logLevel)
if err != nil {
log.Fatal(err)
}
log.SetLevel(level)
if version {
goutil.PrintAppVersion(AppVersion, GitCommit, BuildDate)
return
}
if enableTLS {
if !utils.FileExist(CAFile) {
log.Fatalf("failed to read ca cert file: %s", CAFile)
}
if !utils.FileExist(certFile) {
log.Fatalf("failed to read server cert file: %s", certFile)
return
}
if !utils.FileExist(keyFile) {
log.Fatalf("failed to read server key file: %s", keyFile)
return
}
}
certificate := auth.Certificate{
CAFile: strings.TrimSpace(CAFile),
CertFile: strings.TrimSpace(certFile),
KeyFile: strings.TrimSpace(keyFile),
}
if runtime.GOOS != "windows" && os.Getuid() == 0 && !allowRoot {
log.Fatal("Do not run gocron-node as root user")
return
}
server.Start(serverAddr, enableTLS, certificate)
}