Skip to content

Commit

Permalink
handle cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
XANi committed Dec 25, 2024
1 parent fb2afe6 commit 05e8e05
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions web/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"io/fs"
"net/http"
"os"
"os/signal"
"strings"
"syscall"
"time"
)

Expand Down Expand Up @@ -128,9 +130,18 @@ func (b *WebBackend) Run() error {
}
b.l.Infof("running on unix socket %s", filename)
// https://github.com/golang/go/issues/70985
// defer is not called on control-c so we need to clean by ourselves
if _, err := os.Stat(filename); err == nil {
os.Remove(filename)
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
for range sigs {
os.Remove(filename)
os.Exit(0)
}
}()
b.l.Errorf("failed starting unix socket: %s", b.r.RunUnix(filename))
}()
}
Expand Down

0 comments on commit 05e8e05

Please sign in to comment.