forked from marcetin/parallelcoin
-
Notifications
You must be signed in to change notification settings - Fork 5
/
pod.go
74 lines (71 loc) · 1.45 KB
/
pod.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
package cmd
import (
"fmt"
// This enables pprof
_ "net/http/pprof"
"os"
"runtime"
"runtime/debug"
"runtime/trace"
"github.com/p9c/pod/app"
"github.com/p9c/pod/pkg/util/interrupt"
"github.com/p9c/pod/pkg/util/limits"
)
// Main is the main entry point for pod
func Main() {
runtime.GOMAXPROCS(runtime.NumCPU() * 3)
debug.SetGCPercent(10)
var e error
if runtime.GOOS != "darwin" {
if e = limits.SetLimits(); E.Chk(e) { // todo: doesn't work on non-linux
_, _ = fmt.Fprintf(os.Stderr, "failed to set limits: %v\n", e)
os.Exit(1)
}
}
var f *os.File
if os.Getenv("POD_TRACE") == "on" {
D.Ln("starting trace")
if f, e = os.Create(fmt.Sprintf("%v.trace", fmt.Sprint(os.Args))); E.Chk(e) {
E.Ln(
"tracing env POD_TRACE=on but we can't write to it",
e,
)
} else {
e = trace.Start(f)
if e != nil {
E.Ln("could not start tracing", e)
} else {
D.Ln("tracing started")
defer trace.Stop()
defer func() {
if e := f.Close(); E.Chk(e) {
}
}()
interrupt.AddHandler(
func() {
D.Ln("stopping trace")
trace.Stop()
e := f.Close()
if e != nil {
}
},
)
}
}
}
res := app.Main()
D.Ln("returning value", res, os.Args)
if os.Getenv("POD_TRACE") == "on" {
D.Ln("stopping trace")
trace.Stop()
defer func() {
if e := f.Close(); E.Chk(e) {
}
}()
}
if res != 0 {
E.Ln("quitting with error")
// D.Ln(interrupt.GoroutineDump())
os.Exit(res)
}
}