2016-01-25 06:41:39 +01:00
|
|
|
// Copyright 2016 The Chihaya Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by the BSD 2-Clause license,
|
|
|
|
// which can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
2016-08-01 22:51:48 +02:00
|
|
|
"runtime/pprof"
|
2016-01-25 06:41:39 +01:00
|
|
|
"syscall"
|
|
|
|
|
2016-03-03 02:18:55 +01:00
|
|
|
"github.com/chihaya/chihaya"
|
2016-01-25 06:41:39 +01:00
|
|
|
"github.com/chihaya/chihaya/server"
|
|
|
|
"github.com/chihaya/chihaya/tracker"
|
2016-02-16 01:49:25 +01:00
|
|
|
|
2016-04-04 06:27:30 +02:00
|
|
|
// Servers
|
2016-02-16 01:49:25 +01:00
|
|
|
_ "github.com/chihaya/chihaya/server/http"
|
2016-03-03 02:59:01 +01:00
|
|
|
_ "github.com/chihaya/chihaya/server/prometheus"
|
2016-03-02 22:24:38 +01:00
|
|
|
_ "github.com/chihaya/chihaya/server/store"
|
|
|
|
_ "github.com/chihaya/chihaya/server/store/memory"
|
2016-04-04 06:27:30 +02:00
|
|
|
|
|
|
|
// Middleware
|
|
|
|
_ "github.com/chihaya/chihaya/middleware/deniability"
|
2016-04-03 00:44:45 +02:00
|
|
|
_ "github.com/chihaya/chihaya/middleware/varinterval"
|
2016-03-02 22:24:38 +01:00
|
|
|
_ "github.com/chihaya/chihaya/server/store/middleware/client"
|
2016-03-29 17:54:23 +02:00
|
|
|
_ "github.com/chihaya/chihaya/server/store/middleware/infohash"
|
2016-04-03 02:22:15 +02:00
|
|
|
_ "github.com/chihaya/chihaya/server/store/middleware/ip"
|
|
|
|
_ "github.com/chihaya/chihaya/server/store/middleware/response"
|
2016-04-18 21:49:55 +02:00
|
|
|
_ "github.com/chihaya/chihaya/server/store/middleware/swarm"
|
2016-01-25 06:41:39 +01:00
|
|
|
)
|
|
|
|
|
2016-08-01 22:51:48 +02:00
|
|
|
var (
|
|
|
|
configPath string
|
|
|
|
cpuprofile string
|
|
|
|
)
|
2016-01-25 06:41:39 +01:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.StringVar(&configPath, "config", "", "path to the configuration file")
|
2016-08-01 22:51:48 +02:00
|
|
|
flag.StringVar(&cpuprofile, "cpuprofile", "", "path to cpu profile output")
|
2016-01-25 06:41:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
2016-08-01 22:51:48 +02:00
|
|
|
if cpuprofile != "" {
|
|
|
|
log.Println("profiling...")
|
|
|
|
f, err := os.Create(cpuprofile)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
pprof.StartCPUProfile(f)
|
|
|
|
defer pprof.StopCPUProfile()
|
|
|
|
}
|
|
|
|
|
2016-03-03 02:18:55 +01:00
|
|
|
cfg, err := chihaya.OpenConfigFile(configPath)
|
2016-01-25 06:41:39 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("failed to load config: " + err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
tkr, err := tracker.NewTracker(&cfg.Tracker)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("failed to create tracker: " + err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
pool, err := server.StartPool(cfg.Servers, tkr)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("failed to create server pool: " + err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
shutdown := make(chan os.Signal)
|
|
|
|
signal.Notify(shutdown, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
<-shutdown
|
|
|
|
pool.Stop()
|
|
|
|
}
|