8d92c288e2
* separate sadb migration, add version check * update checkversion to do same validation as migration * changes per CR * add sa migration to storj-sim * add different debug port in storj-sim for migration * add wait for exit for storj-sim migration * update sa docker entrypoint to support migration * storj-sim satellite parts all wait for migration * upgrade golang-migrate/migrate to v4 because bug * fix go mod tidy
85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
// Copyright (C) 2019 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/storj/internal/version"
|
|
"storj.io/storj/pkg/process"
|
|
"storj.io/storj/pkg/revocation"
|
|
"storj.io/storj/satellite"
|
|
"storj.io/storj/satellite/accounting/live"
|
|
"storj.io/storj/satellite/metainfo"
|
|
"storj.io/storj/satellite/satellitedb"
|
|
)
|
|
|
|
func cmdAPIRun(cmd *cobra.Command, args []string) (err error) {
|
|
ctx, _ := process.Ctx(cmd)
|
|
log := zap.L()
|
|
|
|
identity, err := runCfg.Identity.Load()
|
|
if err != nil {
|
|
zap.S().Fatal(err)
|
|
}
|
|
|
|
db, err := satellitedb.New(log.Named("db"), runCfg.Database)
|
|
if err != nil {
|
|
return errs.New("Error starting master database on satellite api: %+v", err)
|
|
}
|
|
defer func() {
|
|
err = errs.Combine(err, db.Close())
|
|
}()
|
|
|
|
pointerDB, err := metainfo.NewStore(log.Named("pointerdb"), runCfg.Config.Metainfo.DatabaseURL)
|
|
if err != nil {
|
|
return errs.New("Error creating metainfo database on satellite api: %+v", err)
|
|
}
|
|
defer func() {
|
|
err = errs.Combine(err, db.Close())
|
|
}()
|
|
|
|
revocationDB, err := revocation.NewDBFromCfg(runCfg.Config.Server.Config)
|
|
if err != nil {
|
|
return errs.New("Error creating revocation database on satellite api: %+v", err)
|
|
}
|
|
defer func() {
|
|
err = errs.Combine(err, revocationDB.Close())
|
|
}()
|
|
|
|
accountingCache, err := live.NewCache(log.Named("live-accounting"), runCfg.LiveAccounting)
|
|
if err != nil {
|
|
return errs.New("Error creating live accounting cache on satellite api: %+v", err)
|
|
}
|
|
defer func() {
|
|
err = errs.Combine(err, accountingCache.Close())
|
|
}()
|
|
|
|
peer, err := satellite.NewAPI(log, identity, db, pointerDB, revocationDB, accountingCache, &runCfg.Config, version.Build)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = peer.Version.CheckVersion(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := process.InitMetricsWithCertPath(ctx, log, nil, runCfg.Identity.CertPath); err != nil {
|
|
zap.S().Warn("Failed to initialize telemetry batcher on satellite api: ", err)
|
|
}
|
|
|
|
err = db.CheckVersion()
|
|
if err != nil {
|
|
zap.S().Fatal("failed satellite database version check: ", err)
|
|
return errs.New("Error checking version for satellitedb: %+v", err)
|
|
}
|
|
|
|
runError := peer.Run(ctx)
|
|
closeError := peer.Close()
|
|
return errs.Combine(runError, closeError)
|
|
}
|