reflector.go/cmd/peer.go

43 lines
963 B
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"
)
func init() {
var cmd = &cobra.Command{
2018-02-02 22:48:57 +01:00
Use: "peer",
Short: "Run peer server",
Run: peerCmd,
}
rootCmd.AddCommand(cmd)
2018-02-02 22:48:57 +01:00
}
func peerCmd(cmd *cobra.Command, args []string) {
db := new(db.SQL)
err := db.Connect(globalConfig.DBConn)
2018-02-02 22:48:57 +01:00
checkErr(err)
s3 := store.NewS3BlobStore(globalConfig.AwsID, globalConfig.AwsSecret, globalConfig.BucketRegion, globalConfig.BucketName)
2018-02-02 22:48:57 +01:00
combo := store.NewDBBackedS3Store(s3, db)
peerServer := peer.NewServer(combo)
if err := peerServer.Start("localhost:" + strconv.Itoa(peer.DefaultPort)); 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
}