mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
Startup notification (#250)
Stop the caddy message and start our own init notifications. Log the version of CoreDNS when starting up. Fix all middleware's setup functions so that return the error prefixed with *which* middleware was failing; leads to better debuggable errors when starting up.
This commit is contained in:
@@ -15,12 +15,13 @@ import (
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
|
||||
// Plug in CoreDNS
|
||||
_ "github.com/miekg/coredns/core"
|
||||
"github.com/miekg/coredns/core"
|
||||
)
|
||||
|
||||
func init() {
|
||||
caddy.TrapSignals()
|
||||
caddy.DefaultConfigFile = "Corefile"
|
||||
caddy.Quiet = true // don't show init stuff from caddy
|
||||
setVersion()
|
||||
|
||||
flag.StringVar(&conf, "conf", "", "Corefile to load (default \""+caddy.DefaultConfigFile+"\")")
|
||||
@@ -28,7 +29,7 @@ func init() {
|
||||
flag.BoolVar(&plugins, "plugins", false, "List installed plugins")
|
||||
flag.StringVar(&logfile, "log", "", "Process log file")
|
||||
flag.StringVar(&caddy.PidFile, "pidfile", "", "Path to write pid file")
|
||||
flag.BoolVar(&caddy.Quiet, "quiet", false, "Quiet mode (no initialization output)")
|
||||
flag.BoolVar(&core.Quiet, "quiet", false, "Quiet mode (no initialization output)")
|
||||
flag.BoolVar(&version, "version", false, "Show version")
|
||||
|
||||
caddy.RegisterCaddyfileLoader("flag", caddy.LoaderFunc(confLoader))
|
||||
@@ -58,12 +59,10 @@ func Run() {
|
||||
MaxBackups: 10,
|
||||
})
|
||||
}
|
||||
log.SetFlags(log.LstdFlags)
|
||||
|
||||
if version {
|
||||
fmt.Printf("%s-%s\n", caddy.AppName, caddy.AppVersion)
|
||||
if devBuild && gitShortStat != "" {
|
||||
fmt.Printf("%s\n%s\n", gitShortStat, gitFilesModified)
|
||||
}
|
||||
showVersion()
|
||||
os.Exit(0)
|
||||
}
|
||||
if plugins {
|
||||
@@ -72,8 +71,7 @@ func Run() {
|
||||
}
|
||||
|
||||
// Set CPU cap
|
||||
err := setCPU(cpu)
|
||||
if err != nil {
|
||||
if err := setCPU(cpu); err != nil {
|
||||
mustLogFatal(err)
|
||||
}
|
||||
|
||||
@@ -89,10 +87,35 @@ func Run() {
|
||||
mustLogFatal(err)
|
||||
}
|
||||
|
||||
logVersion()
|
||||
|
||||
// Twiddle your thumbs
|
||||
instance.Wait()
|
||||
}
|
||||
|
||||
// startNotification will log CoreDNS' version to the log.
|
||||
func startupNotification() {
|
||||
if core.Quiet {
|
||||
return
|
||||
}
|
||||
logVersion()
|
||||
}
|
||||
|
||||
func showVersion() {
|
||||
fmt.Printf("%s-%s\n", caddy.AppName, caddy.AppVersion)
|
||||
if devBuild && gitShortStat != "" {
|
||||
fmt.Printf("%s\n%s\n", gitShortStat, gitFilesModified)
|
||||
}
|
||||
}
|
||||
|
||||
// logVersion logs the version that is starting.
|
||||
func logVersion() {
|
||||
log.Printf("[INFO] %s-%s starting\n", caddy.AppName, caddy.AppVersion)
|
||||
if devBuild && gitShortStat != "" {
|
||||
log.Printf("[INFO] %s\n%s\n", gitShortStat, gitFilesModified)
|
||||
}
|
||||
}
|
||||
|
||||
// mustLogFatal wraps log.Fatal() in a way that ensures the
|
||||
// output is always printed to stderr so the user can see it
|
||||
// if the user is still there, even if the process log was not
|
||||
|
||||
Reference in New Issue
Block a user