reflector.go/cmd/peer.go

54 lines
1.1 KiB
Go
Raw 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 {
db := new(db.SQL)
err = db.Connect(globalConfig.DBConn)
checkErr(err)
combo := store.NewDBBackedStore(s3, db)
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
}