func proxyServer() { loadConfigOrDie() debug.SetGCPercent(config.GCPercent) db, err := kvl.Open(config.Proxy.Database.Type, config.Proxy.Database.DSN) if err != nil { log.Fatalf("Couldn't connect to %v database: %v", config.Proxy.Database.Type, err) } defer db.Close() var h http.Handler h, err = proxyserver.New(db, config.Proxy.Scrubbers, config.Proxy.CacheSize) if err != nil { log.Fatalf("Couldn't initialize handler: %v", err) } h = httputil.NewLimitParallelism(config.Proxy.ParallelRequests, h) h = httputil.AddDebugHandlers(h, config.Proxy.Debug) if !config.Proxy.DisableHTTPLogging { h = httputil.LogHTTPRequests(h) } if config.Proxy.Listen == "none" { for { time.Sleep(time.Hour) } } else { serveOrDie(config.Proxy.Listen, h) } }
func chunkServer() { loadConfigOrDie() debug.SetGCPercent(config.GCPercent) stores := make([]store.Store, len(config.Chunk.Dirs)) for i := range config.Chunk.Dirs { dir := config.Chunk.Dirs[i] construct := func() store.Store { log.Printf("Trying to open store at %v", dir) start := time.Now() ds, err := storedir.OpenDirectory( dir, config.Chunk.Scrubber.SleepPerFile.Duration, config.Chunk.Scrubber.SleepPerByte.Duration, ) if err != nil { log.Printf("Couldn't open store at %v: %v", dir, err) return nil } dur := time.Now().Sub(start) log.Printf("Store at %v opened with UUID %v in %v", dir, uuid.Fmt(ds.UUID()), dur) return ds } stores[i] = store.NewRetryStore(construct, time.Second*15) } var h http.Handler var err error h, err = chunkserver.New(stores) if err != nil { log.Fatalf("Couldn't initialize handler: %v", err) } h = httputil.NewLimitParallelism(config.Chunk.ParallelRequests, h) h = httputil.AddDebugHandlers(h, config.Chunk.Debug) if !config.Chunk.DisableHTTPLogging { h = httputil.LogHTTPRequests(h) } serveOrDie(config.Chunk.Listen, h) }