Server: Add link to documentation for unix domain sockets #4673 #4684

see https://github.com/photoprism/photoprism/discussions/4710

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2025-01-09 15:17:45 +01:00
parent b1f60c3d37
commit 43398f7eec

View File

@@ -7,7 +7,6 @@ import (
"fmt"
"net"
"net/http"
"os"
"time"
"golang.org/x/crypto/acme/autocert"
@@ -108,6 +107,7 @@ func Start(ctx context.Context, conf *config.Config) {
var unixAddr *net.UnixAddr
var err error
// Create a Unix socket and attach the server to it.
if unixAddr, err = net.ResolveUnixAddr("unix", unixSocket); err != nil {
log.Errorf("server: invalid unix socket (%s)", err)
return
@@ -115,6 +115,8 @@ func Start(ctx context.Context, conf *config.Config) {
log.Errorf("server: failed to listen on unix socket (%s)", err)
return
} else {
// Listen on Unix socket, which should be automatically closed and removed after use:
// https://pkg.go.dev/net#UnixListener.SetUnlinkOnClose.
server = &http.Server{
Addr: unixSocket,
Handler: router,
@@ -182,17 +184,6 @@ func Start(ctx context.Context, conf *config.Config) {
if err != nil {
log.Errorf("server: shutdown failed (%s)", err)
}
// Remove the Unix Domain Socket file if it exists on shutdown
if unixSocket := conf.HttpSocket(); unixSocket != "" {
if _, err := os.Stat(unixSocket); err == nil {
if err := os.Remove(unixSocket); err != nil {
log.Errorf("server: failed to remove unix socket file %s: %v", unixSocket, err)
} else {
log.Debugf("server: removed unix socket file %s", unixSocket)
}
}
}
}
// StartHttp starts the Web server in http mode.