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"
|
|
|
|
)
|
|
|
|
|
2019-09-11 18:30:01 +02:00
|
|
|
var peerNoDB bool
|
|
|
|
|
2018-02-02 22:48:57 +01:00
|
|
|
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,
|
|
|
|
}
|
2019-09-11 18:30:01 +02:00
|
|
|
cmd.Flags().BoolVar(&peerNoDB, "nodb", false, "Don't connect to a db and don't use a db-backed blob store")
|
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) {
|
2019-09-11 18:30:01 +02:00
|
|
|
var err error
|
2018-02-02 22:48:57 +01:00
|
|
|
|
2018-05-30 03:38:55 +02:00
|
|
|
s3 := store.NewS3BlobStore(globalConfig.AwsID, globalConfig.AwsSecret, globalConfig.BucketRegion, globalConfig.BucketName)
|
2019-09-11 18:30:01 +02:00
|
|
|
peerServer := peer.NewServer(s3)
|
|
|
|
|
|
|
|
if !peerNoDB {
|
|
|
|
db := new(db.SQL)
|
|
|
|
err = db.Connect(globalConfig.DBConn)
|
|
|
|
checkErr(err)
|
|
|
|
|
2019-10-03 22:58:17 +02:00
|
|
|
combo := store.NewDBBackedStore(s3, db)
|
2019-09-11 18:30:01 +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
|
|
|
}
|