more signals handled

This commit is contained in:
boyska 2018-11-10 17:41:45 +01:00
parent c70e28ff27
commit 86bdeed4a2

View file

@ -3,10 +3,12 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"log"
"net" "net"
"net/http" "net/http"
"os" "os"
"os/signal" "os/signal"
"syscall"
"git.lattuga.net/boyska/circolog" "git.lattuga.net/boyska/circolog"
syslog "gopkg.in/mcuadros/go-syslog.v2" syslog "gopkg.in/mcuadros/go-syslog.v2"
@ -29,7 +31,7 @@ func main() {
flag.Parse() flag.Parse()
interrupt := make(chan os.Signal, 1) interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt) signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
hub := circolog.NewHub(*bufsize) hub := circolog.NewHub(*bufsize)
handler := syslog.NewChannelHandler(hub.LogMessages) handler := syslog.NewChannelHandler(hub.LogMessages)
@ -85,7 +87,8 @@ func main() {
for { for {
select { select {
case <-interrupt: case sig := <-interrupt:
log.Println("Quitting because of signal", sig)
server.Kill() server.Kill()
if err := httpServer.Close(); err != nil { if err := httpServer.Close(); err != nil {
fmt.Fprintln(os.Stderr, "Error closing http server:", err) fmt.Fprintln(os.Stderr, "Error closing http server:", err)