mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-13 08:08:36 -07:00
Reorganize main package structure per discussion
This commit is contained in:
72
chihaya.go
Normal file
72
chihaya.go
Normal file
@@ -0,0 +1,72 @@
|
||||
// Copyright 2014 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 chihaya
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"github.com/chihaya/chihaya/config"
|
||||
"github.com/chihaya/chihaya/http"
|
||||
|
||||
// See the README for how to import custom drivers.
|
||||
_ "github.com/chihaya/chihaya/drivers/backend/noop"
|
||||
_ "github.com/chihaya/chihaya/drivers/tracker/memory"
|
||||
)
|
||||
|
||||
var (
|
||||
maxProcs int
|
||||
profile string
|
||||
configPath string
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.IntVar(&maxProcs, "maxprocs", runtime.NumCPU(), "maximum parallel threads")
|
||||
flag.StringVar(&profile, "profile", "", "if non-empty, path to write profiling data")
|
||||
flag.StringVar(&configPath, "config", "", "path to the configuration file")
|
||||
}
|
||||
|
||||
func Boot() {
|
||||
defer glog.Flush()
|
||||
|
||||
flag.Parse()
|
||||
|
||||
runtime.GOMAXPROCS(maxProcs)
|
||||
glog.V(1).Info("Set max threads to ", maxProcs)
|
||||
|
||||
if profile != "" {
|
||||
f, err := os.Create(profile)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to create profile file: %s\n", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
pprof.StartCPUProfile(f)
|
||||
glog.Info("Started profiling")
|
||||
|
||||
defer func() {
|
||||
pprof.StopCPUProfile()
|
||||
glog.Info("Stopped profiling")
|
||||
}()
|
||||
}
|
||||
|
||||
cfg, err := config.Open(configPath)
|
||||
if err != nil {
|
||||
glog.Fatalf("Failed to parse configuration file: %s\n", err)
|
||||
}
|
||||
|
||||
if cfg == &config.DefaultConfig {
|
||||
glog.V(1).Info("Using default config")
|
||||
} else {
|
||||
glog.V(1).Infof("Loaded config file: %s", configPath)
|
||||
}
|
||||
|
||||
http.Serve(cfg)
|
||||
glog.Info("Gracefully shut down")
|
||||
}
|
||||
Reference in New Issue
Block a user