2016-11-11 21:48:00 +07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-11-26 20:42:35 +07:00
|
|
|
log "github.com/Sirupsen/logrus"
|
2016-11-11 21:48:00 +07:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2016-11-23 23:07:38 +07:00
|
|
|
// DNSConf is global configuration struct
|
2016-11-17 00:15:36 +07:00
|
|
|
var DNSConf DNSConfig
|
2016-11-11 21:48:00 +07:00
|
|
|
|
2016-11-23 23:07:38 +07:00
|
|
|
// DB is used to access the database functions in acme-dns
|
|
|
|
var DB database
|
2016-11-11 21:48:00 +07:00
|
|
|
|
2016-11-23 23:07:38 +07:00
|
|
|
// RR holds the static DNS records
|
2016-11-11 21:48:00 +07:00
|
|
|
var RR Records
|
|
|
|
|
|
|
|
func main() {
|
2016-11-13 19:50:44 +07:00
|
|
|
// Read global config
|
2016-11-17 00:15:36 +07:00
|
|
|
configTmp, err := readConfig("config.cfg")
|
2016-11-11 21:48:00 +07:00
|
|
|
if err != nil {
|
2016-11-26 20:42:35 +07:00
|
|
|
fmt.Printf("Got error %v\n", err)
|
2016-11-11 21:48:00 +07:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
2016-11-17 00:15:36 +07:00
|
|
|
DNSConf = configTmp
|
2016-11-23 22:11:31 +07:00
|
|
|
|
2016-11-28 02:21:38 +07:00
|
|
|
setupLogging(DNSConf.Logconfig.Format, DNSConf.Logconfig.Level)
|
2016-11-13 19:50:44 +07:00
|
|
|
|
|
|
|
// Read the default records in
|
2016-11-17 00:15:36 +07:00
|
|
|
RR.Parse(DNSConf.General.StaticRecords)
|
2016-11-11 21:48:00 +07:00
|
|
|
|
|
|
|
// Open database
|
2016-11-17 22:52:55 +07:00
|
|
|
err = DB.Init(DNSConf.Database.Engine, DNSConf.Database.Connection)
|
2016-11-11 21:48:00 +07:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("Could not open database [%v]", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
defer DB.DB.Close()
|
|
|
|
|
2016-11-28 02:21:38 +07:00
|
|
|
// DNS server
|
|
|
|
startDNS(DNSConf.General.Listen)
|
2016-11-11 21:48:00 +07:00
|
|
|
|
2016-11-28 03:09:13 +07:00
|
|
|
// HTTP API
|
|
|
|
startHTTPAPI()
|
|
|
|
|
2016-11-11 21:48:00 +07:00
|
|
|
log.Debugf("Shutting down...")
|
|
|
|
}
|