aboutsummaryrefslogtreecommitdiff
path: root/core/sigtrap.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2016-08-19 17:14:17 -0700
committerGravatar GitHub <noreply@github.com> 2016-08-19 17:14:17 -0700
commit9ac3cab1b7b1b1e78f86ce3c6a80fbee312162e6 (patch)
tree437e9755927c33af16276ad2602a6da115f948cb /core/sigtrap.go
parenta1989c35231b0e5ea271b2f68d82c1a63e697cd0 (diff)
downloadcoredns-9ac3cab1b7b1b1e78f86ce3c6a80fbee312162e6.tar.gz
coredns-9ac3cab1b7b1b1e78f86ce3c6a80fbee312162e6.tar.zst
coredns-9ac3cab1b7b1b1e78f86ce3c6a80fbee312162e6.zip
Make CoreDNS a server type plugin for Caddy (#220)
* Make CoreDNS a server type plugin for Caddy Remove code we don't need and port all middleware over. Fix all tests and rework the documentation. Also make `go generate` build a caddy binary which we then copy into our directory. This means `go build`-builds remain working as-is. And new etc instances in each etcd test for better isolation. Fix more tests and rework test.Server with the newer support Caddy offers. Fix Makefile to support new mode of operation.
Diffstat (limited to 'core/sigtrap.go')
-rw-r--r--core/sigtrap.go93
1 files changed, 0 insertions, 93 deletions
diff --git a/core/sigtrap.go b/core/sigtrap.go
deleted file mode 100644
index f40dd971a..000000000
--- a/core/sigtrap.go
+++ /dev/null
@@ -1,93 +0,0 @@
-package core
-
-import (
- "log"
- "os"
- "os/signal"
- "sync"
-
- "github.com/miekg/coredns/server"
-)
-
-// TrapSignals create signal handlers for all applicable signals for this
-// system. If your Go program uses signals, this is a rather invasive
-// function; best to implement them yourself in that case. Signals are not
-// required for the caddy package to function properly, but this is a
-// convenient way to allow the user to control this package of your program.
-func TrapSignals() {
- trapSignalsCrossPlatform()
- trapSignalsPosix()
-}
-
-// trapSignalsCrossPlatform captures SIGINT, which triggers forceful
-// shutdown that executes shutdown callbacks first. A second interrupt
-// signal will exit the process immediately.
-func trapSignalsCrossPlatform() {
- go func() {
- shutdown := make(chan os.Signal, 1)
- signal.Notify(shutdown, os.Interrupt)
-
- for i := 0; true; i++ {
- <-shutdown
-
- if i > 0 {
- log.Println("[INFO] SIGINT: Force quit")
- if PidFile != "" {
- os.Remove(PidFile)
- }
- os.Exit(1)
- }
-
- log.Println("[INFO] SIGINT: Shutting down")
-
- if PidFile != "" {
- os.Remove(PidFile)
- }
-
- go os.Exit(executeShutdownCallbacks("SIGINT"))
- }
- }()
-}
-
-// executeShutdownCallbacks executes the shutdown callbacks as initiated
-// by signame. It logs any errors and returns the recommended exit status.
-// This function is idempotent; subsequent invocations always return 0.
-func executeShutdownCallbacks(signame string) (exitCode int) {
- shutdownCallbacksOnce.Do(func() {
- serversMu.Lock()
- errs := server.ShutdownCallbacks(servers)
- serversMu.Unlock()
-
- if len(errs) > 0 {
- for _, err := range errs {
- log.Printf("[ERROR] %s shutdown: %v", signame, err)
- }
- exitCode = 1
- }
- })
- return
-}
-
-// executeStartupCallbacks executes the startup callbacks as initiated
-// by signame. This is used when on restart when the child failed to start and
-// all middleware executed their shutdown functions
-func executeStartupCallbacks(signame string) (exitCode int) {
- startupCallbacksOnce.Do(func() {
- serversMu.Lock()
- errs := server.StartupCallbacks(servers)
- serversMu.Unlock()
-
- if len(errs) > 0 {
- for _, err := range errs {
- log.Printf("[ERROR] %s shutdown: %v", signame, err)
- }
- exitCode = 1
- }
- })
- return
-}
-
-var (
- shutdownCallbacksOnce sync.Once
- startupCallbacksOnce sync.Once
-)