-
Notifications
You must be signed in to change notification settings - Fork 665
/
main.go
76 lines (63 loc) · 2.02 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// (c) 2021, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package main
import (
"fmt"
"os"
"syscall"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"github.com/ava-labs/avalanchego/app/process"
"github.com/ava-labs/avalanchego/config"
"github.com/ava-labs/avalanchego/utils"
"github.com/ava-labs/avalanchego/utils/perms"
appPlugin "github.com/ava-labs/avalanchego/app/plugin"
)
// GitCommit should be optionally set at compile time.
var GitCommit string
// main runs an AvalancheGo node.
// If specified in the config, serves a hashicorp plugin that can be consumed by
// the daemon (see avalanchego/main).
func main() {
nodeConfig, processConfig, err := config.GetConfigs(GitCommit)
if err != nil {
fmt.Printf("couldn't get node config: %s\n", err)
os.Exit(1)
}
if processConfig.DisplayVersionAndExit {
fmt.Print(processConfig.VersionStr)
os.Exit(0)
}
// Set the data directory permissions to be read write.
if err := perms.ChmodR(nodeConfig.DBPath, true, perms.ReadWriteExecute); err != nil {
fmt.Printf("failed to restrict the permissions of the database directory with error %s\n", err)
os.Exit(1)
}
if err := perms.ChmodR(nodeConfig.LoggingConfig.Directory, true, perms.ReadWriteExecute); err != nil {
fmt.Printf("failed to restrict the permissions of the log directory with error %s\n", err)
os.Exit(1)
}
app := process.NewApp(nodeConfig) // Create node wrapper
if processConfig.PluginMode { // Serve as a plugin
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: appPlugin.Handshake,
Plugins: map[string]plugin.Plugin{
"nodeProcess": appPlugin.New(app),
},
GRPCServer: plugin.DefaultGRPCServer, // A non-nil value here enables gRPC serving for this plugin
Logger: hclog.New(&hclog.LoggerOptions{
Level: hclog.Error,
}),
})
return
}
fmt.Println(process.Header)
_ = utils.HandleSignals(
func(os.Signal) {
app.Stop()
},
syscall.SIGINT, syscall.SIGTERM,
)
exitCode := app.Start() // Start the node
os.Exit(exitCode)
}