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:
Ian Roberts 2024-10-19 16:55:39 +01:00
parent be8389ed4d
commit fdee28a812

View file

@ -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: