2018-02-02 22:48:57 +01:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2018-06-07 05:48:07 +02:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2018-02-02 22:48:57 +01:00
|
|
|
"strconv"
|
2018-06-07 05:48:07 +02:00
|
|
|
"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"
|
|
|
|
|
2018-02-08 19:33:52 +01:00
|
|
|
log "github.com/sirupsen/logrus"
|
2018-02-02 22:48:57 +01:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2018-02-08 19:33:52 +01:00
|
|
|
var cmd = &cobra.Command{
|
2018-02-02 22:48:57 +01:00
|
|
|
Use: "peer",
|
|
|
|
Short: "Run peer server",
|
|
|
|
Run: peerCmd,
|
|
|
|
}
|
2018-05-30 03:38:55 +02:00
|
|
|
rootCmd.AddCommand(cmd)
|
2018-02-02 22:48:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func peerCmd(cmd *cobra.Command, args []string) {
|
|
|
|
db := new(db.SQL)
|
2018-05-30 03:38:55 +02:00
|
|
|
err := db.Connect(globalConfig.DBConn)
|
2018-02-02 22:48:57 +01:00
|
|
|
checkErr(err)
|
|
|
|
|
2018-05-30 03:38:55 +02:00
|
|
|
s3 := store.NewS3BlobStore(globalConfig.AwsID, globalConfig.AwsSecret, globalConfig.BucketRegion, globalConfig.BucketName)
|
2018-02-02 22:48:57 +01:00
|
|
|
combo := store.NewDBBackedS3Store(s3, db)
|
2018-06-07 05:48:07 +02:00
|
|
|
peerServer := peer.NewServer(combo)
|
2018-06-15 04:30:37 +02:00
|
|
|
|
2018-06-21 17:26:48 +02:00
|
|
|
err = peerServer.Start(":" + strconv.Itoa(peer.DefaultPort))
|
2018-06-15 04:30:37 +02:00
|
|
|
if err != nil {
|
2018-06-07 05:48:07 +02:00
|
|
|
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
|
|
|
}
|