forked from boyska/circolog
Clean sockets at exit.
This commit is contained in:
parent
3d463823e3
commit
9728b236ed
1 changed files with 11 additions and 2 deletions
|
@ -17,12 +17,18 @@ import (
|
|||
syslog "gopkg.in/mcuadros/go-syslog.v2"
|
||||
)
|
||||
|
||||
var socketsToRemove []string
|
||||
|
||||
func cleanSocket(socket string) {
|
||||
if err := os.Remove(socket); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error cleaning", socket, ":", err)
|
||||
}
|
||||
}
|
||||
|
||||
func removeAtExit(socket string) {
|
||||
socketsToRemove = append(socketsToRemove, socket)
|
||||
}
|
||||
|
||||
func main() {
|
||||
var err error
|
||||
var logFmt formatter.SyslogRFC
|
||||
|
@ -77,7 +83,7 @@ func main() {
|
|||
fmt.Fprintln(os.Stderr, "Error binding HTTP unix domain socket", err)
|
||||
return
|
||||
}
|
||||
defer cleanSocket(*querySocket)
|
||||
removeAtExit(*querySocket)
|
||||
go func() {
|
||||
if err := httpQueryServer.Serve(unixListener); err != nil && err != http.ErrServerClosed {
|
||||
fmt.Fprintln(os.Stderr, "error binding", *querySocket, ":", err)
|
||||
|
@ -102,7 +108,7 @@ func main() {
|
|||
fmt.Fprintln(os.Stderr, "Error binding HTTP unix domain socket", err)
|
||||
return
|
||||
}
|
||||
defer cleanSocket(*ctlSocket)
|
||||
removeAtExit(*ctlSocket)
|
||||
go func() {
|
||||
if err := httpCtlServer.Serve(unixListener); err != nil && err != http.ErrServerClosed {
|
||||
fmt.Fprintln(os.Stderr, "error binding:", err)
|
||||
|
@ -152,6 +158,9 @@ func main() {
|
|||
if err := httpCtlServer.Shutdown(nil); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error closing control server:", err)
|
||||
}
|
||||
for _, socket := range socketsToRemove {
|
||||
cleanSocket(socket)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue