2020-02-07 15:56:59 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
2020-03-23 19:18:20 +00:00
|
|
|
"storj.io/private/process"
|
2020-03-23 19:30:31 +00:00
|
|
|
"storj.io/private/version"
|
2020-02-07 15:56:59 +00:00
|
|
|
"storj.io/storj/satellite"
|
2021-11-12 20:47:41 +00:00
|
|
|
"storj.io/storj/satellite/metabase"
|
2020-02-07 15:56:59 +00:00
|
|
|
"storj.io/storj/satellite/satellitedb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func cmdAdminRun(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 {
|
2020-10-13 14:49:33 +01:00
|
|
|
log.Error("Failed to load identity.", zap.Error(err))
|
|
|
|
return errs.New("Failed to load identity: %+v", err)
|
2020-02-07 15:56:59 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 13:48:31 +00:00
|
|
|
db, err := satellitedb.Open(ctx, log.Named("db"), runCfg.Database, satellitedb.Options{
|
2020-12-04 10:24:39 +00:00
|
|
|
ApplicationName: "satellite-admin",
|
2020-02-07 15:56:59 +00:00
|
|
|
APIKeysLRUOptions: runCfg.APIKeysLRUOptions(),
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return errs.New("Error starting master database on satellite api: %+v", err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
err = errs.Combine(err, db.Close())
|
|
|
|
}()
|
|
|
|
|
2022-10-28 15:56:20 +01:00
|
|
|
metabaseDB, err := metabase.Open(ctx, log.Named("metabase"), runCfg.Config.Metainfo.DatabaseURL,
|
|
|
|
runCfg.Config.Metainfo.Metabase("satellite-admin"))
|
2021-11-12 20:47:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return errs.New("Error creating metabase connection on satellite api: %+v", err)
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
err = errs.Combine(err, metabaseDB.Close())
|
|
|
|
}()
|
|
|
|
|
|
|
|
peer, err := satellite.NewAdmin(log, identity, db, metabaseDB, version.Build, &runCfg.Config, process.AtomicLevel(cmd))
|
2020-02-07 15:56:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-21 17:41:54 +00:00
|
|
|
_, err = peer.Version.Service.CheckVersion(ctx)
|
2020-02-07 15:56:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := process.InitMetricsWithCertPath(ctx, log, nil, runCfg.Identity.CertPath); err != nil {
|
2020-04-13 10:31:17 +01:00
|
|
|
log.Warn("Failed to initialize telemetry batcher on satellite admin", zap.Error(err))
|
2020-03-30 16:22:32 +01:00
|
|
|
}
|
|
|
|
|
2021-11-12 20:47:41 +00:00
|
|
|
err = metabaseDB.CheckVersion(ctx)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Failed metabase database version check.", zap.Error(err))
|
|
|
|
return errs.New("failed metabase version check: %+v", err)
|
|
|
|
}
|
|
|
|
|
2020-02-07 15:56:59 +00:00
|
|
|
err = db.CheckVersion(ctx)
|
|
|
|
if err != nil {
|
2020-10-13 14:49:33 +01:00
|
|
|
log.Error("Failed satellite database version check.", zap.Error(err))
|
2020-02-07 15:56:59 +00:00
|
|
|
return errs.New("Error checking version for satellitedb: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
runError := peer.Run(ctx)
|
|
|
|
closeError := peer.Close()
|
|
|
|
return errs.Combine(runError, closeError)
|
|
|
|
}
|