-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
69 lines (59 loc) · 2.03 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
// Copyright 2019 the orbs-network-go authors
// This file is part of the orbs-network-go library in the Orbs project.
//
// This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.
// The above notice should be included in all copies or substantial portions of the software.
package main
import (
"context"
"flag"
"fmt"
"github.com/orbs-network/orbs-network-go/bootstrap"
"github.com/orbs-network/orbs-network-go/config"
"github.com/orbs-network/orbs-network-go/instrumentation"
"github.com/orbs-network/orbs-network-go/synchronization/supervised"
"github.com/orbs-network/scribe/log"
"github.com/pkg/errors"
"os"
)
func main() {
logger := instrumentation.GetBootstrapCrashLogger()
var node *bootstrap.Node
func() { // context of bootstrap crash logging
defer func() {
if r := recover(); r != nil {
logger.Error("unexpected error during bootstrap", log.Error(errors.Errorf("unknown error: %v", r)))
os.Exit(8)
}
}()
httpAddress := flag.String("listen", ":8080", "ip address and port for http server")
silentLog := flag.Bool("silent", false, "disable output to stdout")
pathToLog := flag.String("log", "", "path/to/node.log")
version := flag.Bool("version", false, "returns information about version")
var filePaths config.FilesPaths
flag.Var(&filePaths, "config", "path/to/config.json")
flag.Parse()
if *version {
fmt.Println(config.GetVersion())
os.Exit(0)
}
cfg, err := config.GetNodeConfigFromFiles(filePaths, *httpAddress)
if err != nil {
logger.Error("error reading configuration", log.Error(err))
os.Exit(1)
}
logger = instrumentation.GetLogger(*pathToLog, *silentLog, cfg)
node = bootstrap.NewNode(
cfg,
logger,
)
supervised.NewShutdownListener(logger, node).ListenToOSShutdownSignal()
}()
defer func() {
if r := recover(); r != nil {
logger.Error("unexpected error in main goroutine", log.Error(errors.Errorf("unknown error: %v", r)))
os.Exit(2)
}
}()
node.WaitUntilShutdown(context.Background())
}