cleanup old unix socket and set write permissions
This commit is contained in:
parent
a479dab96c
commit
0b1d455bc5
14
main.go
14
main.go
@ -4,8 +4,10 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -146,10 +148,20 @@ func main() {
|
||||
}
|
||||
})
|
||||
if unixSocketPath != "" {
|
||||
// Remove old one
|
||||
if err := os.Remove(unixSocketPath); err != nil && !errors.Is(err, fs.ErrNotExist) {
|
||||
log.Panicf("Failed to remove unix socket : %q err: %v\n", unixSocketPath, err)
|
||||
}
|
||||
|
||||
l, err := net.Listen("unix", unixSocketPath)
|
||||
if err != nil {
|
||||
log.Panicf("Unable to listen to unix socket in path: %q err:%v\n", unixSocketPath, err)
|
||||
log.Panicf("Unable to listen to unix socket : %q err: %v\n", unixSocketPath, err)
|
||||
}
|
||||
|
||||
if err = os.Chmod(unixSocketPath, 0666); err != nil {
|
||||
log.Panicf("Failed to set permission of unix socket %q err: %v\n", unixSocketPath, err)
|
||||
}
|
||||
|
||||
log.Panicln(http.Serve(l, nil))
|
||||
}
|
||||
log.Panicln(http.ListenAndServe(fmt.Sprintf(":%v", port), nil))
|
||||
|
Loading…
Reference in New Issue
Block a user