2021-02-01 10:13:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2021-02-05 06:25:12 +00:00
|
|
|
"net/http"
|
2021-02-01 10:13:38 +00:00
|
|
|
"os"
|
2021-08-09 07:18:30 +00:00
|
|
|
"os/signal"
|
2021-12-31 05:59:09 +00:00
|
|
|
"runtime"
|
2021-08-09 07:18:30 +00:00
|
|
|
"time"
|
2021-02-01 10:13:38 +00:00
|
|
|
|
2021-09-16 03:31:04 +00:00
|
|
|
_ "net/http/pprof"
|
2021-02-05 06:25:12 +00:00
|
|
|
|
2021-02-01 10:13:38 +00:00
|
|
|
"github.com/RaaLabs/steward"
|
2022-06-18 05:35:59 +00:00
|
|
|
"github.com/pkg/profile"
|
2021-02-01 10:13:38 +00:00
|
|
|
)
|
|
|
|
|
2021-09-10 08:04:25 +00:00
|
|
|
// Use ldflags to set version
|
|
|
|
// env CONFIGFOLDER=./etc/ go run -ldflags "-X main.version=v0.1.10" --race ./cmd/steward/.
|
|
|
|
// or
|
|
|
|
// env GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=v0.1.10" -o steward
|
|
|
|
var version string
|
|
|
|
|
2021-02-01 10:13:38 +00:00
|
|
|
func main() {
|
2022-12-26 06:22:42 +00:00
|
|
|
defer profile.Start(profile.BlockProfile).Stop()
|
2022-06-18 05:35:59 +00:00
|
|
|
//defer profile.Start(profile.CPUProfile, profile.ProfilePath(".")).Stop()
|
|
|
|
//defer profile.Start(profile.TraceProfile, profile.ProfilePath(".")).Stop()
|
2022-12-26 06:22:42 +00:00
|
|
|
//defer profile.Start(profile.MemProfile, profile.MemProfileRate(1)).Stop()
|
2021-08-16 11:01:12 +00:00
|
|
|
|
2021-03-01 19:49:43 +00:00
|
|
|
c := steward.NewConfiguration()
|
2023-04-12 07:56:08 +00:00
|
|
|
err := c.CheckFlags(version)
|
2021-03-24 09:14:17 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("%v\n", err)
|
|
|
|
return
|
|
|
|
}
|
2021-02-01 10:13:38 +00:00
|
|
|
|
2021-02-25 12:08:10 +00:00
|
|
|
// Start profiling if profiling port is specified
|
2021-03-01 19:49:43 +00:00
|
|
|
if c.ProfilingPort != "" {
|
2021-02-05 06:25:12 +00:00
|
|
|
go func() {
|
2021-03-01 19:49:43 +00:00
|
|
|
http.ListenAndServe("localhost:"+c.ProfilingPort, nil)
|
2021-02-05 06:25:12 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-12-31 05:59:09 +00:00
|
|
|
if c.SetBlockProfileRate != 0 {
|
2021-12-31 06:02:50 +00:00
|
|
|
runtime.SetBlockProfileRate(c.SetBlockProfileRate)
|
2021-12-31 05:59:09 +00:00
|
|
|
}
|
|
|
|
|
2021-09-10 08:04:25 +00:00
|
|
|
s, err := steward.NewServer(c, version)
|
2021-02-01 10:13:38 +00:00
|
|
|
if err != nil {
|
2021-03-12 09:41:03 +00:00
|
|
|
log.Printf("%v\n", err)
|
2021-02-01 10:13:38 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2021-08-09 07:18:30 +00:00
|
|
|
// Start up the server
|
|
|
|
go s.Start()
|
|
|
|
|
|
|
|
// Wait for ctrl+c to stop the server.
|
|
|
|
sigCh := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigCh, os.Interrupt)
|
|
|
|
|
|
|
|
// Block and wait for CTRL+C
|
|
|
|
sig := <-sigCh
|
2021-09-23 03:46:25 +00:00
|
|
|
log.Printf("Got exit signal, terminating all processes, %v\n", sig)
|
2021-08-09 07:18:30 +00:00
|
|
|
|
|
|
|
// Adding a safety function here so we can make sure that all processes
|
|
|
|
// are stopped after a given time if the context cancelation hangs.
|
|
|
|
go func() {
|
|
|
|
time.Sleep(time.Second * 10)
|
|
|
|
log.Printf("error: doing a non graceful shutdown of all processes..\n")
|
|
|
|
os.Exit(1)
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Stop all processes.
|
|
|
|
s.Stop()
|
2021-02-01 10:13:38 +00:00
|
|
|
}
|