-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
47 lines (43 loc) · 1.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
package main
import (
"context"
"fmt"
"os"
"os/signal"
"runtime/debug"
"runtime/pprof"
"syscall"
"github.com/groupe-edf/watchdog/cmd"
"github.com/groupe-edf/watchdog/internal/util"
logger "github.com/sirupsen/logrus"
)
var profile bool
func main() {
interruptChan := make(chan os.Signal, 1)
signal.Notify(interruptChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
ctx := util.InitializeContext()
ctx, cancel := context.WithCancel(ctx)
go func() {
<-interruptChan
cancel()
}()
// Intercept application panic
defer func() {
if r := recover(); r != nil {
fmt.Println("something went worng, please contact your system administrator \n", string(debug.Stack()))
os.Exit(0)
}
}()
if profile {
prof, err := os.Create("watchdog.prof")
if err != nil {
logger.Fatalf("could not create cpu profile: %v", err)
}
defer prof.Close()
if err := pprof.StartCPUProfile(prof); err != nil {
logger.Fatalf("could not start cpu profile: %v", err)
}
defer pprof.StopCPUProfile()
}
_ = cmd.Execute(ctx)
}