mirror of
https://github.com/adnanh/webhook.git
synced 2025-05-23 05:42:30 +00:00
added signal watcher
This commit is contained in:
parent
f5276ea955
commit
7b3ebcc9cb
1 changed files with 16 additions and 0 deletions
16
webhook.go
16
webhook.go
|
@ -6,7 +6,10 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/adnanh/webhook/hooks"
|
"github.com/adnanh/webhook/hooks"
|
||||||
|
@ -26,6 +29,7 @@ const (
|
||||||
var (
|
var (
|
||||||
webhooks *hooks.Hooks
|
webhooks *hooks.Hooks
|
||||||
appStart time.Time
|
appStart time.Time
|
||||||
|
signalChannel chan<- os.Signal
|
||||||
ip = flag.String("ip", "", "ip the webhook server should listen on")
|
ip = flag.String("ip", "", "ip the webhook server should listen on")
|
||||||
port = flag.Int("port", 9000, "port the webhook server should listen on")
|
port = flag.Int("port", 9000, "port the webhook server should listen on")
|
||||||
hooksFilename = flag.String("hooks", "hooks.json", "path to the json file containing defined hooks the webhook should serve")
|
hooksFilename = flag.String("hooks", "hooks.json", "path to the json file containing defined hooks the webhook should serve")
|
||||||
|
@ -41,6 +45,18 @@ func init() {
|
||||||
martini.Env = "production"
|
martini.Env = "production"
|
||||||
|
|
||||||
l4g.AddFilter("file", l4g.FINE, fileLogWriter)
|
l4g.AddFilter("file", l4g.FINE, fileLogWriter)
|
||||||
|
|
||||||
|
signalChannel := make(chan os.Signal, 2)
|
||||||
|
|
||||||
|
signal.Notify(signalChannel, os.Interrupt, syscall.SIGTERM)
|
||||||
|
go func() {
|
||||||
|
sig := <-signalChannel
|
||||||
|
switch sig {
|
||||||
|
case syscall.SIGTERM, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGHUP, syscall.SIGABRT:
|
||||||
|
l4g.Info("Caught kill signal, stopping webhook.", sig)
|
||||||
|
l4g.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue