MCPcopy
hub / github.com/caddyserver/caddy / trapSignalsCrossPlatform

Function trapSignalsCrossPlatform

sigtrap.go:37–54  ·  view source on GitHub ↗

trapSignalsCrossPlatform captures SIGINT or interrupt (depending on the OS), which initiates a graceful shutdown. A second SIGINT or interrupt will forcefully exit the process immediately.

()

Source from the content-addressed store, hash-verified

35// on the OS), which initiates a graceful shutdown. A second SIGINT
36// or interrupt will forcefully exit the process immediately.
37func trapSignalsCrossPlatform() {
38 go func() {
39 shutdown := make(chan os.Signal, 1)
40 signal.Notify(shutdown, os.Interrupt)
41
42 for i := 0; true; i++ {
43 <-shutdown
44
45 if i > 0 {
46 Log().Warn("force quit", zap.String("signal", "SIGINT"))
47 os.Exit(ExitCodeForceQuit)
48 }
49
50 Log().Info("shutting down", zap.String("signal", "SIGINT"))
51 go exitProcessFromSignal("SIGINT")
52 }
53 }()
54}
55
56// exitProcessFromSignal exits the process from a system signal.
57func exitProcessFromSignal(sigName string) {

Callers 1

TrapSignalsFunction · 0.85

Calls 3

LogFunction · 0.85
exitProcessFromSignalFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected