Ejemplo n.º 1
0
func InitEnv(configPath string) {

	if !filetool.IsExist(configPath) {
		log.Warn("configuration file[%s] is nonexistent", configPath)
		UseSystemConfig = true
	}

	if !UseSystemConfig {
		var err error
		Config, err = config.NewConfig("ini", configPath)
		if err != nil {
			log.Fetal("configuration file[%s] cannot parse. ", configPath)
			os.Exit(1)
		}
	}

	if !UseSystemConfig {
		log.SetLevelWithDefault(Config.String("log::level"), "info")
	} else {
		log.SetLevel("info")
	}

	initCfg()

	defaultPidPath := "/var/run/falcon_eye/falcon_eye.pid"
	if !UseSystemConfig {
		if iniPidPath := Config.String("common::pid"); iniPidPath != "" {
			defaultPidPath = iniPidPath
		}
	}
	systool.WritePidFile(defaultPidPath)

	runtime.GOMAXPROCS(runtime.NumCPU())
}
Ejemplo n.º 2
0
func initVersion() {
	var err error
	Version, err = filetool.ReadFileToStringNoLn("VERSION")
	if err != nil {
		log.Fetal("read VERSION file fail")
		os.Exit(1)
	}
}
Ejemplo n.º 3
0
func StartHttp() {

	p, err := strconv.Atoi(global.HttpPort)
	if err != nil {
		logtool.Fetal("port[%s] format error", global.HttpPort)
		os.Exit(1)
	}

	if funcs.PortIsListen(int64(p)) {
		logtool.Fetal("port[%d] is in listen", p)
		os.Exit(1)
	}

	m = martini.Classic()

	m.Use(render.Renderer(render.Options{
		Funcs: []template.FuncMap{{
			"nl2br":      nl2br,
			"htmlquote":  htmlQuote,
			"str2html":   str2html,
			"dateformat": dateFormat,
		}},
	}))

	m.Get("/healthz", func() string {
		return "ok"
	})

	m.Get("/", func(re render.Render) {
		m := make(map[string]string)
		m["version"] = global.Version
		re.HTML(200, "index", m)
	})

	CfgKernelRouter()
	CfgSystemRouter()
	CfgCpuRouter()
	CfgMemRouter()
	CfgDfRouter()
	CfgNetRouter()
	CfgIORouter()

	logtool.Info("use http port: %s", global.HttpPort)
	http.ListenAndServe(":"+global.HttpPort, m)
}
Ejemplo n.º 4
0
func InitEnv() {
	var err error

	// log
	logLevel := Cfg.String("log_level")
	log.SetLevelWithDefault(logLevel, "info")

	// cache
	Cache, err = cache.NewCache("memory", `{"interval":60}`)
	if err != nil {
		log.Fetal("cache init fail :(")
		os.Exit(1)
	}
	blogCacheExpire, _ = Cfg.Int64("blog_cache_expire")
	catalogCacheExpire, _ = Cfg.Int64("catalog_cache_expire")

	// database
	dbUser := Cfg.String("db_user")
	dbPass := Cfg.String("db_pass")
	dbHost := Cfg.String("db_host")
	dbPort := Cfg.String("db_port")
	dbName := Cfg.String("db_name")
	maxIdleConn, _ := Cfg.Int("db_max_idle_conn")
	maxOpenConn, _ := Cfg.Int("db_max_open_conn")
	dbLink := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbUser, dbPass, dbHost, dbPort, dbName) + "&loc=Asia%2FChongqing"

	orm.RegisterDriver("mysql", orm.DR_MySQL)
	orm.RegisterDataBase("default", "mysql", dbLink, maxIdleConn, maxOpenConn)

	RunMode = Cfg.String("runmode")
	if RunMode == "dev" {
		orm.Debug = true
	}

	initCfg()
}