Commit 7d5b6b96 authored by Matthew Holt's avatar Matthew Holt

Make signal trapping optional

Go programs using the caddy package may not want the it to capture all the signals...
parent 7b064535
......@@ -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 (
......
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)
......
package caddy
func trapSignalsPosix() {}
......@@ -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
......
......@@ -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+")")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment