Fix syslogd-socket handling at interrupt
This commit is contained in:
parent
36f531a58a
commit
f66e07e873
1 changed files with 26 additions and 4 deletions
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue