reflector.go/cmd/peer.go

56 lines
1.2 KiB
Go
Raw Permalink Normal View History

2018-02-02 22:48:57 +01:00
package cmd
import (
"os"
"os/signal"
2018-02-02 22:48:57 +01:00
"strconv"
"syscall"
2018-02-02 22:48:57 +01:00
"github.com/lbryio/reflector.go/db"
"github.com/lbryio/reflector.go/peer"
"github.com/lbryio/reflector.go/store"
log "github.com/sirupsen/logrus"
2018-02-02 22:48:57 +01:00
"github.com/spf13/cobra"
)
var peerNoDB bool
2018-02-02 22:48:57 +01:00
func init() {
var cmd = &cobra.Command{
2018-02-02 22:48:57 +01:00
Use: "peer",
Short: "Run peer server",
Run: peerCmd,
}
cmd.Flags().BoolVar(&peerNoDB, "nodb", false, "Don't connect to a db and don't use a db-backed blob store")
rootCmd.AddCommand(cmd)
2018-02-02 22:48:57 +01:00
}
func peerCmd(cmd *cobra.Command, args []string) {
var err error
2018-02-02 22:48:57 +01:00
s3 := store.NewS3Store(globalConfig.AwsID, globalConfig.AwsSecret, globalConfig.BucketRegion, globalConfig.BucketName)
peerServer := peer.NewServer(s3)
if !peerNoDB {
2021-01-06 16:43:35 +01:00
db := &db.SQL{
LogQueries: log.GetLevel() == log.DebugLevel,
}
err = db.Connect(globalConfig.DBConn)
checkErr(err)
combo := store.NewDBBackedStore(s3, db, false)
peerServer = peer.NewServer(combo)
}
err = peerServer.Start(":" + strconv.Itoa(peer.DefaultPort))
if err != nil {
log.Fatal(err)
}
interruptChan := make(chan os.Signal, 1)
signal.Notify(interruptChan, os.Interrupt, syscall.SIGTERM)
<-interruptChan
peerServer.Shutdown()
2018-02-02 22:48:57 +01:00
}