2020-07-10 17:17:51 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-01-12 14:05:08 +03:00
|
|
|
"context"
|
2020-09-16 10:45:08 +03:00
|
|
|
"flag"
|
2020-08-21 18:01:59 +03:00
|
|
|
"log"
|
|
|
|
|
2021-05-11 12:25:14 +03:00
|
|
|
"github.com/nspcc-dev/neofs-node/misc"
|
2021-01-15 13:28:37 +03:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
2020-08-21 14:32:03 +03:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/grace"
|
2021-01-12 14:05:08 +03:00
|
|
|
"go.uber.org/zap"
|
2020-07-10 17:17:51 +03:00
|
|
|
)
|
|
|
|
|
2020-08-21 18:01:59 +03:00
|
|
|
func fatalOnErr(err error) {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 17:17:51 +03:00
|
|
|
func main() {
|
2020-09-16 10:45:08 +03:00
|
|
|
configFile := flag.String("config", "", "path to config")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
c := initCfg(*configFile)
|
2020-08-21 18:01:59 +03:00
|
|
|
|
2021-01-11 18:17:06 +03:00
|
|
|
initApp(c)
|
2020-08-24 12:40:32 +03:00
|
|
|
|
2021-01-15 13:28:37 +03:00
|
|
|
c.setHealthStatus(control.HealthStatus_STARTING)
|
|
|
|
|
2020-08-24 12:40:32 +03:00
|
|
|
bootUp(c)
|
|
|
|
|
2021-01-15 13:28:37 +03:00
|
|
|
c.setHealthStatus(control.HealthStatus_READY)
|
|
|
|
|
2020-08-24 12:40:32 +03:00
|
|
|
wait(c)
|
|
|
|
|
2021-01-15 13:28:37 +03:00
|
|
|
c.setHealthStatus(control.HealthStatus_SHUTTING_DOWN)
|
|
|
|
|
2020-08-24 12:40:32 +03:00
|
|
|
shutdown(c)
|
|
|
|
}
|
|
|
|
|
2021-01-11 18:17:06 +03:00
|
|
|
func initApp(c *cfg) {
|
2021-01-12 14:05:08 +03:00
|
|
|
c.ctx, c.ctxCancel = context.WithCancel(grace.NewGracefulContext(nil))
|
2020-08-21 18:01:59 +03:00
|
|
|
|
2020-08-24 12:40:32 +03:00
|
|
|
initGRPC(c)
|
|
|
|
|
2020-10-08 16:17:50 +03:00
|
|
|
initNetmapService(c)
|
2020-08-24 12:40:32 +03:00
|
|
|
initAccountingService(c)
|
2020-08-24 17:07:08 +03:00
|
|
|
initContainerService(c)
|
2020-08-24 18:51:42 +03:00
|
|
|
initSessionService(c)
|
2021-03-23 21:54:00 +03:00
|
|
|
initReputationService(c)
|
2020-08-25 16:37:10 +03:00
|
|
|
initObjectService(c)
|
2020-10-02 16:18:38 +03:00
|
|
|
initProfiler(c)
|
2021-03-15 16:11:40 +03:00
|
|
|
initMetrics(c)
|
2021-01-13 16:46:39 +03:00
|
|
|
initControlService(c)
|
2020-10-21 12:26:16 +03:00
|
|
|
|
2020-11-30 18:35:37 +03:00
|
|
|
fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Open())
|
|
|
|
fatalOnErr(c.cfgObject.cfgLocalStorage.localStorage.Init())
|
|
|
|
|
2020-10-21 12:26:16 +03:00
|
|
|
listenMorphNotifications(c)
|
2020-08-24 12:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func bootUp(c *cfg) {
|
2020-08-22 14:03:45 +03:00
|
|
|
serveGRPC(c)
|
2020-08-31 18:20:02 +03:00
|
|
|
bootstrapNode(c)
|
2020-10-03 12:57:02 +03:00
|
|
|
startWorkers(c)
|
2021-04-15 17:57:29 +03:00
|
|
|
startBlockTimers(c)
|
2020-08-24 12:40:32 +03:00
|
|
|
}
|
2020-07-10 17:17:51 +03:00
|
|
|
|
2020-08-24 12:40:32 +03:00
|
|
|
func wait(c *cfg) {
|
2021-05-11 12:25:14 +03:00
|
|
|
c.log.Info("application started",
|
|
|
|
zap.String("build time", misc.Build),
|
|
|
|
zap.String("version", misc.Version),
|
|
|
|
zap.String("debug", misc.Debug),
|
|
|
|
)
|
2020-09-25 15:34:17 +03:00
|
|
|
|
2021-01-12 14:05:08 +03:00
|
|
|
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()))
|
|
|
|
}
|
2020-08-24 12:40:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func shutdown(c *cfg) {
|
2021-01-18 11:56:14 +03:00
|
|
|
for _, closer := range c.closers {
|
|
|
|
closer()
|
|
|
|
}
|
2020-08-22 14:03:45 +03:00
|
|
|
|
|
|
|
c.wg.Wait()
|
2020-07-10 17:17:51 +03:00
|
|
|
}
|
2021-01-18 11:56:14 +03:00
|
|
|
|
|
|
|
func (c *cfg) onShutdown(f func()) {
|
|
|
|
c.closers = append(c.closers, f)
|
|
|
|
}
|