|
@@ -16,7 +16,7 @@ import (
|
|
|
|
|
|
func cleanSocket(socket string) {
|
|
func cleanSocket(socket string) {
|
|
if err := os.Remove(socket); err != nil {
|
|
if err := os.Remove(socket); err != nil {
|
|
- fmt.Fprintln(os.Stderr, socket, ":", err)
|
|
|
|
|
|
+ fmt.Fprintln(os.Stderr, "Error cleaning", socket, ":", err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -28,13 +28,15 @@ func main() {
|
|
syslogAddr := flag.String("syslog-addr", "127.0.0.1:9514", "Address:port where to listen for syslog messages")
|
|
syslogAddr := flag.String("syslog-addr", "127.0.0.1:9514", "Address:port where to listen for syslog messages")
|
|
queryAddr := flag.String("query-addr", "127.0.0.1:9080", "Address:port where to bind the query service")
|
|
queryAddr := flag.String("query-addr", "127.0.0.1:9080", "Address:port where to bind the query service")
|
|
querySocket := flag.String("query-socket", "", "Path to a unix domain socket for the HTTP server; recommended for security reasons!")
|
|
querySocket := flag.String("query-socket", "", "Path to a unix domain socket for the HTTP server; recommended for security reasons!")
|
|
|
|
+ ctlSocket := flag.String("ctl-socket", "/tmp/circologd-ctl.sock", "Path to a unix domain socket for the control server; leave empty to disable")
|
|
flag.Parse()
|
|
flag.Parse()
|
|
|
|
|
|
interrupt := make(chan os.Signal, 1)
|
|
interrupt := make(chan os.Signal, 1)
|
|
- signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
|
|
+ signal.Notify(interrupt, syscall.SIGINT, syscall.SIGUSR1, syscall.SIGTERM)
|
|
|
|
|
|
hub := circolog.NewHub(*bufsize)
|
|
hub := circolog.NewHub(*bufsize)
|
|
handler := syslog.NewChannelHandler(hub.LogMessages)
|
|
handler := syslog.NewChannelHandler(hub.LogMessages)
|
|
|
|
+ go hub.Run()
|
|
|
|
|
|
server := syslog.NewServer()
|
|
server := syslog.NewServer()
|
|
server.SetFormat(syslog.RFC5424)
|
|
server.SetFormat(syslog.RFC5424)
|
|
@@ -57,10 +59,8 @@ func main() {
|
|
fmt.Fprintln(os.Stderr, "argh", err)
|
|
fmt.Fprintln(os.Stderr, "argh", err)
|
|
os.Exit(1)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
- go hub.Run()
|
|
|
|
|
|
|
|
- setupHTTP(hub)
|
|
|
|
- httpServer := http.Server{Handler: nil}
|
|
|
|
|
|
+ httpQueryServer := http.Server{Handler: setupHTTP(hub)}
|
|
if *querySocket != "" {
|
|
if *querySocket != "" {
|
|
fmt.Printf("Binding address `%s` [http]\n", *querySocket)
|
|
fmt.Printf("Binding address `%s` [http]\n", *querySocket)
|
|
unixListener, err := net.Listen("unix", *querySocket)
|
|
unixListener, err := net.Listen("unix", *querySocket)
|
|
@@ -70,31 +70,62 @@ func main() {
|
|
}
|
|
}
|
|
defer cleanSocket(*querySocket)
|
|
defer cleanSocket(*querySocket)
|
|
go func() {
|
|
go func() {
|
|
- if err := httpServer.Serve(unixListener); err != nil {
|
|
|
|
- fmt.Fprintln(os.Stderr, "error binding:", err)
|
|
|
|
|
|
+ if err := httpQueryServer.Serve(unixListener); err != nil && err != http.ErrServerClosed {
|
|
|
|
+ fmt.Fprintln(os.Stderr, "error binding", *querySocket, ":", err)
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
} else {
|
|
} else {
|
|
- httpServer.Addr = *queryAddr
|
|
|
|
|
|
+ httpQueryServer.Addr = *queryAddr
|
|
fmt.Printf("Binding address `%s` [http]\n", *queryAddr)
|
|
fmt.Printf("Binding address `%s` [http]\n", *queryAddr)
|
|
go func() {
|
|
go func() {
|
|
- err := httpServer.ListenAndServe()
|
|
|
|
- if err != nil {
|
|
|
|
|
|
+ err := httpQueryServer.ListenAndServe()
|
|
|
|
+ if err != nil && err != http.ErrServerClosed {
|
|
|
|
+ fmt.Fprintln(os.Stderr, "error binding", *queryAddr, ":", err)
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ httpCtlServer := http.Server{Handler: setupHTTPCtl(hub)}
|
|
|
|
+ if *ctlSocket != "" {
|
|
|
|
+ fmt.Printf("Binding address `%s` [http]\n", *ctlSocket)
|
|
|
|
+ unixListener, err := net.Listen("unix", *ctlSocket)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Fprintln(os.Stderr, "Error binding HTTP unix domain socket", err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ defer cleanSocket(*ctlSocket)
|
|
|
|
+ go func() {
|
|
|
|
+ if err := httpCtlServer.Serve(unixListener); err != nil && err != http.ErrServerClosed {
|
|
fmt.Fprintln(os.Stderr, "error binding:", err)
|
|
fmt.Fprintln(os.Stderr, "error binding:", err)
|
|
}
|
|
}
|
|
}()
|
|
}()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // TODO: now we are ready
|
|
|
|
+
|
|
for {
|
|
for {
|
|
select {
|
|
select {
|
|
case sig := <-interrupt:
|
|
case sig := <-interrupt:
|
|
- log.Println("Quitting because of signal", sig)
|
|
|
|
- server.Kill()
|
|
|
|
- if err := httpServer.Close(); err != nil {
|
|
|
|
- fmt.Fprintln(os.Stderr, "Error closing http server:", err)
|
|
|
|
|
|
+ if sig == syscall.SIGUSR1 {
|
|
|
|
+ hub.Commands <- circolog.HubFullCommand{Command: circolog.CommandPauseToggle}
|
|
|
|
+ resp := <-hub.Responses
|
|
|
|
+ if resp.Value.(bool) {
|
|
|
|
+ log.Println("resumed")
|
|
|
|
+ } else {
|
|
|
|
+ log.Println("paused")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if sig == syscall.SIGTERM || sig == syscall.SIGINT {
|
|
|
|
+ log.Println("Quitting because of signal", sig)
|
|
|
|
+ server.Kill()
|
|
|
|
+ if err := httpQueryServer.Shutdown(nil); err != nil {
|
|
|
|
+ fmt.Fprintln(os.Stderr, "Error closing http server:", err)
|
|
|
|
+ }
|
|
|
|
+ if err := httpCtlServer.Shutdown(nil); err != nil {
|
|
|
|
+ fmt.Fprintln(os.Stderr, "Error closing control server:", err)
|
|
|
|
+ }
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- return
|
|
|
|
- default:
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|