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 (
|
2015-10-13 11:33:51 +00:00
|
|
|
logger *GoDNSLogger
|
2013-07-23 11:10:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
2015-10-13 11:33:51 +00:00
|
|
|
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()
|
|
|
|
|
2015-10-13 11:33:51 +00:00
|
|
|
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:
|
2015-10-13 11:33:51 +00:00
|
|
|
logger.Info("signal received, stopping")
|
2013-07-23 11:10:38 +00:00
|
|
|
break forever
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-10-13 11:33:51 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-10-13 11:33:51 +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())
|
|
|
|
}
|