cloud-game/cmd/worker/main.go
sergystepanov 30d104ee98
Add version info into the apps (#330)
Both worker and coordinator display version number in the console during startup. Coordinator displays its version number in the top right corner of the index.html page.
2021-07-16 18:13:20 +03:00

60 lines
1.2 KiB
Go

package main
import (
"context"
goflag "flag"
"math/rand"
"os"
"os/signal"
"syscall"
"time"
config "github.com/giongto35/cloud-game/v2/pkg/config/worker"
"github.com/giongto35/cloud-game/v2/pkg/thread"
"github.com/giongto35/cloud-game/v2/pkg/util/logging"
"github.com/giongto35/cloud-game/v2/pkg/worker"
"github.com/golang/glog"
flag "github.com/spf13/pflag"
)
var Version = ""
func init() {
rand.Seed(time.Now().UTC().UnixNano())
}
func run() {
conf := config.NewConfig()
flag.CommandLine.AddGoFlagSet(goflag.CommandLine)
conf.ParseFlags()
logging.Init()
defer logging.Flush()
ctx, cancelCtx := context.WithCancel(context.Background())
glog.Infof("[worker] version: %v", Version)
glog.V(4).Info("[worker] Initialization")
glog.V(4).Infof("[worker] Local configuration %+v", conf)
wrk := worker.New(ctx, conf)
wrk.Run()
signals := make(chan os.Signal, 1)
done := make(chan struct{}, 1)
signal.Notify(signals, os.Interrupt, syscall.SIGTERM)
go func() {
sig := <-signals
glog.V(4).Infof("[worker] Shutting down [os:%v]", sig)
done <- struct{}{}
}()
<-done
wrk.Shutdown()
cancelCtx()
}
func main() {
thread.MainWrapMaybe(run)
}