mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-10 09:02:30 +08:00
Ensure unix socket is removed before we startup
This commit is contained in:
parent
2dfd42f80c
commit
b15efb5201
1 changed files with 15 additions and 0 deletions
15
app.go
15
app.go
|
@ -351,6 +351,16 @@ func (h *Headscale) httpAuthenticationMiddleware(c *gin.Context) {
|
|||
// c.Next()
|
||||
}
|
||||
|
||||
// ensureUnixSocketIsAbsent will check if the given path for headscales unix socket is clear
|
||||
// and will remove it if it is not.
|
||||
func (h *Headscale) ensureUnixSocketIsAbsent() error {
|
||||
// File does not exist, all fine
|
||||
if _, err := os.Stat(h.cfg.UnixSocket); errors.Is(err, os.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
return os.Remove(h.cfg.UnixSocket)
|
||||
}
|
||||
|
||||
// Serve launches a GIN server with the Headscale API.
|
||||
func (h *Headscale) Serve() error {
|
||||
var err error
|
||||
|
@ -360,6 +370,11 @@ func (h *Headscale) Serve() error {
|
|||
|
||||
defer cancel()
|
||||
|
||||
err = h.ensureUnixSocketIsAbsent()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
socketListener, err := net.Listen("unix", h.cfg.UnixSocket)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
Loading…
Reference in a new issue