68 lines
2.0 KiB
Go
68 lines
2.0 KiB
Go
|
// Copyright (C) 2022 Storj Labs, Inc.
|
||
|
// See LICENSE for copying information.
|
||
|
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/spf13/cobra"
|
||
|
"github.com/zeebo/errs"
|
||
|
"go.uber.org/zap"
|
||
|
|
||
|
"storj.io/private/process"
|
||
|
"storj.io/storj/satellite"
|
||
|
"storj.io/storj/satellite/metabase"
|
||
|
"storj.io/storj/satellite/satellitedb"
|
||
|
)
|
||
|
|
||
|
func cmdRangedLoopRun(cmd *cobra.Command, args []string) (err error) {
|
||
|
ctx, _ := process.Ctx(cmd)
|
||
|
log := zap.L()
|
||
|
|
||
|
runCfg.Debug.Address = *process.DebugAddrFlag
|
||
|
|
||
|
identity, err := runCfg.Identity.Load()
|
||
|
if err != nil {
|
||
|
log.Error("Failed to load identity.", zap.Error(err))
|
||
|
return errs.New("Failed to load identity: %+v", err)
|
||
|
}
|
||
|
|
||
|
db, err := satellitedb.Open(ctx, log.Named("db"), runCfg.Database, satellitedb.Options{ApplicationName: "satellite-rangedloop"})
|
||
|
if err != nil {
|
||
|
return errs.New("Error starting master database on satellite rangedloop: %+v", err)
|
||
|
}
|
||
|
defer func() {
|
||
|
err = errs.Combine(err, db.Close())
|
||
|
}()
|
||
|
|
||
|
metabaseDB, err := metabase.Open(ctx, log.Named("metabase"), runCfg.Metainfo.DatabaseURL, runCfg.Metainfo.Metabase("satellite-rangedloop"))
|
||
|
if err != nil {
|
||
|
return errs.New("Error creating metabase connection: %+v", err)
|
||
|
}
|
||
|
defer func() {
|
||
|
err = errs.Combine(err, metabaseDB.Close())
|
||
|
}()
|
||
|
|
||
|
peer, err := satellite.NewRangedLoop(log, identity, db, metabaseDB, &runCfg.Config, process.AtomicLevel(cmd))
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
if err := process.InitMetricsWithHostname(ctx, log, nil); err != nil {
|
||
|
log.Warn("Failed to initialize telemetry on satellite rangedloop", zap.Error(err))
|
||
|
}
|
||
|
|
||
|
if err := metabaseDB.CheckVersion(ctx); err != nil {
|
||
|
log.Error("Failed metabase database version check.", zap.Error(err))
|
||
|
return errs.New("failed metabase version check: %+v", err)
|
||
|
}
|
||
|
|
||
|
if err := db.CheckVersion(ctx); err != nil {
|
||
|
log.Error("Failed satellite database version check.", zap.Error(err))
|
||
|
return errs.New("Error checking version for satellitedb: %+v", err)
|
||
|
}
|
||
|
|
||
|
runError := peer.Run(ctx)
|
||
|
closeError := peer.Close()
|
||
|
return errs.Combine(runError, closeError)
|
||
|
}
|