mirror of
https://github.com/adnanh/webhook.git
synced 2025-06-24 13:28:31 +00:00
fix: clean up Unix socket file before exit
If webhook is restarted with the same settings but the socket file has not been deleted, webhook will be unable to bind and will exit with an error.
This commit is contained in:
parent
be8389ed4d
commit
fdee28a812
1 changed files with 11 additions and 0 deletions
11
signals.go
11
signals.go
|
@ -1,3 +1,4 @@
|
|||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package main
|
||||
|
@ -6,6 +7,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
|
@ -43,6 +45,15 @@ func watchForSignals() {
|
|||
log.Print(err)
|
||||
}
|
||||
}
|
||||
if socket != "" && !strings.HasPrefix(socket, "@") {
|
||||
// we've been listening on a named Unix socket, delete it
|
||||
// before we exit so subsequent runs can re-bind the same
|
||||
// socket path
|
||||
err := os.Remove(socket)
|
||||
if err != nil {
|
||||
log.Printf("Failed to remove socket file %s: %v", socket, err)
|
||||
}
|
||||
}
|
||||
os.Exit(0)
|
||||
|
||||
default:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue