71fcbd3ed4
Update node network status via update status by getting the latest network map and finding the node in it. This step is performed at the start of the application and upon notification of a new epoch. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
82 lines
1.3 KiB
Go
82 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"log"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/grace"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
func fatalOnErr(err error) {
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
configFile := flag.String("config", "", "path to config")
|
|
flag.Parse()
|
|
|
|
c := initCfg(*configFile)
|
|
|
|
initApp(c)
|
|
|
|
bootUp(c)
|
|
|
|
wait(c)
|
|
|
|
shutdown(c)
|
|
}
|
|
|
|
func initApp(c *cfg) {
|
|
c.ctx, c.ctxCancel = context.WithCancel(grace.NewGracefulContext(nil))
|
|
|
|
initGRPC(c)
|
|
|
|
initNetmapService(c)
|
|
initAccountingService(c)
|
|
initContainerService(c)
|
|
initSessionService(c)
|
|
initObjectService(c)
|
|
initProfiler(c)
|
|
initControlService(c)
|
|
|
|
fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Open())
|
|
fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Init())
|
|
|
|
listenMorphNotifications(c)
|
|
}
|
|
|
|
func bootUp(c *cfg) {
|
|
serveProfiler(c)
|
|
serveGRPC(c)
|
|
bootstrapNode(c)
|
|
startWorkers(c)
|
|
}
|
|
|
|
func wait(c *cfg) {
|
|
c.log.Info("application started")
|
|
|
|
select {
|
|
case <-c.ctx.Done(): // graceful shutdown
|
|
case err := <-c.internalErr: // internal application error
|
|
close(c.internalErr)
|
|
c.ctxCancel()
|
|
|
|
c.log.Warn("internal application error",
|
|
zap.String("message", err.Error()))
|
|
}
|
|
}
|
|
|
|
func shutdown(c *cfg) {
|
|
c.cfgGRPC.server.GracefulStop()
|
|
c.cfgControlService.server.GracefulStop()
|
|
|
|
c.log.Info("gRPC server stopped")
|
|
|
|
goOffline(c)
|
|
|
|
c.wg.Wait()
|
|
}
|