1
0
Fork 0
forked from boyska/circolog

Fix syslogd-socket handling at interrupt

This commit is contained in:
Blallo 2018-11-10 16:32:12 +01:00
parent 36f531a58a
commit f66e07e873
No known key found for this signature in database
GPG key ID: 0CBE577C9B72DC3F

View file

@ -6,11 +6,18 @@ import (
"net"
"net/http"
"os"
"os/signal"
"git.lattuga.net/boyska/circolog"
syslog "gopkg.in/mcuadros/go-syslog.v2"
)
func cleanSocket(socket string) {
if err := os.Remove(socket); err != nil {
fmt.Fprintln(os.Stderr, socket, ":", err)
}
}
func main() {
var err error
syslogSocketPath := flag.String("syslogd-socket", "", "The socket to listen to syslog addresses")
@ -21,6 +28,9 @@ func main() {
querySocket := flag.String("query-socket", "", "Path to a unix domain socket for the HTTP server; recommended for security reasons!")
flag.Parse()
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
hub := circolog.NewHub(*bufsize)
handler := syslog.NewChannelHandler(hub.LogMessages)
@ -32,6 +42,7 @@ func main() {
fmt.Fprintln(os.Stderr, "argh", err)
os.Exit(1)
}
defer cleanSocket(*syslogSocketPath)
fmt.Printf("Binding socket `%s` [syslog]\n", *syslogSocketPath)
} else {
fmt.Printf("Binding address `%s` [syslog]\n", *syslogAddr)
@ -53,11 +64,22 @@ func main() {
if err != nil {
fmt.Fprintln(os.Stderr, "Error binding HTTP unix domain socket", err)
}
defer os.Remove(*querySocket)
http.Serve(unixListener, nil)
go http.Serve(unixListener, nil)
} else {
fmt.Printf("Binding address `%s` [http]\n", *queryAddr)
http.ListenAndServe(*queryAddr, nil)
go http.ListenAndServe(*queryAddr, nil)
}
for {
select {
case <-interrupt:
server.Kill()
//server.Wait()
if *syslogSocketPath != "" {
}
return
default:
}
}
server.Wait()
}