mirror of
https://github.com/caddyserver/caddy.git
synced 2025-02-02 14:17:01 +01:00
Make signal trapping optional
Go programs using the caddy package may not want the it to capture all the signals...
This commit is contained in:
parent
7b064535bf
commit
7d5b6b96ea
7 changed files with 23 additions and 9 deletions
|
@ -11,9 +11,6 @@
|
|||
//
|
||||
// You should use caddy.Wait() to wait for all Caddy servers
|
||||
// to quit before your process exits.
|
||||
//
|
||||
// Importing this package has the side-effect of trapping signals.
|
||||
// It has to do this in order to perform shutdowns or reloads.
|
||||
package caddy
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package caddy
|
||||
|
||||
// Restart restarts Caddy forcefully using newCaddyfile,
|
||||
// or, if nil, the current/existing Caddyfile is reused.
|
||||
func Restart(newCaddyfile Input) error {
|
||||
if newCaddyfile == nil {
|
||||
caddyfileMu.Lock()
|
||||
|
|
|
@ -9,10 +9,20 @@ import (
|
|||
"github.com/mholt/caddy/server"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Trap interrupt signal (cross-platform); triggers forceful shutdown
|
||||
// that executes shutdown callbacks first. A second interrupt signal
|
||||
// will exit the process immediately.
|
||||
// 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)
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
"syscall"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Trap all POSIX-only signals
|
||||
// trapSignalsPosix captures POSIX-only signals.
|
||||
func trapSignalsPosix() {
|
||||
go func() {
|
||||
sigchan := make(chan os.Signal, 1)
|
||||
signal.Notify(sigchan, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGUSR1)
|
||||
|
|
3
caddy/sigtrap_windows.go
Normal file
3
caddy/sigtrap_windows.go
Normal file
|
@ -0,0 +1,3 @@
|
|||
package caddy
|
||||
|
||||
func trapSignalsPosix() {}
|
1
dist/CHANGES.txt
vendored
1
dist/CHANGES.txt
vendored
|
@ -12,6 +12,7 @@ CHANGES
|
|||
- New -log flag to enable process log
|
||||
- New -pidfile flag to enable writing pidfile
|
||||
- New -grace flag to customize the graceful shutdown timeout
|
||||
- New support for SIGHUP, SIGTERM, and SIGQUIT signals
|
||||
- browse: Render filenames with multiple whitespace properly
|
||||
- markdown: Include Last-Modified header in response
|
||||
- markdown: Render tables, strikethrough, and fenced code blocks
|
||||
|
|
1
main.go
1
main.go
|
@ -30,6 +30,7 @@ const (
|
|||
)
|
||||
|
||||
func init() {
|
||||
caddy.TrapSignals()
|
||||
flag.BoolVar(&letsencrypt.Agreed, "agree", false, "Agree to Let's Encrypt Subscriber Agreement")
|
||||
flag.StringVar(&letsencrypt.CAUrl, "ca", "https://acme-staging.api.letsencrypt.org/directory", "Certificate authority ACME server")
|
||||
flag.StringVar(&conf, "conf", "", "Configuration file to use (default="+caddy.DefaultConfigFile+")")
|
||||
|
|
Loading…
Reference in a new issue