godns/main.go

61 lines
854 B
Go
Raw Normal View History

2013-07-23 11:10:38 +00:00
package main
import (
"os"
"os/signal"
2013-07-25 04:32:57 +00:00
"runtime"
2013-07-23 11:10:38 +00:00
"time"
)
var (
logger *GoDNSLogger
2013-07-23 11:10:38 +00:00
)
func main() {
initLogger()
2013-07-23 11:10:38 +00:00
server := &Server{
host: settings.Server.Host,
port: settings.Server.Port,
rTimeout: 5 * time.Second,
wTimeout: 5 * time.Second,
}
server.Run()
logger.Info("godns %s start", settings.Version)
2013-07-25 04:32:57 +00:00
2013-07-23 11:10:38 +00:00
sig := make(chan os.Signal)
signal.Notify(sig, os.Interrupt)
forever:
for {
select {
case <-sig:
logger.Info("signal received, stopping")
2013-07-23 11:10:38 +00:00
break forever
}
}
}
func initLogger() {
logger = NewLogger()
if settings.Log.Stdout {
logger.SetLogger("console", nil)
}
if settings.Log.File != "" {
config := map[string]interface{}{"file": settings.Log.File}
logger.SetLogger("file", config)
2013-07-23 11:10:38 +00:00
}
logger.SetLevel(settings.Log.LogLevel())
2013-07-23 11:10:38 +00:00
}
2013-07-25 04:32:57 +00:00
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
}