feat: allow setting unix socket mode (#661)

This commit is contained in:
Mr Snake
2025-06-19 00:41:57 +08:00
committed by GitHub
parent 1f65c01b04
commit 7677a3de2c
2 changed files with 16 additions and 0 deletions

View File

@@ -7,6 +7,8 @@ import (
"log" "log"
"net" "net"
"net/http" "net/http"
"os"
"strconv"
"time" "time"
"github.com/pocket-id/pocket-id/backend/frontend" "github.com/pocket-id/pocket-id/backend/frontend"
@@ -119,6 +121,18 @@ func initRouterInternal(db *gorm.DB, svc *services) (utils.Service, error) {
return nil, fmt.Errorf("failed to create %s listener: %w", network, err) return nil, fmt.Errorf("failed to create %s listener: %w", network, err)
} }
// Set the socket mode if using a Unix socket
if network == "unix" && common.EnvConfig.UnixSocketMode != "" {
mode, err := strconv.ParseUint(common.EnvConfig.UnixSocketMode, 8, 32)
if err != nil {
return nil, fmt.Errorf("failed to parse UNIX socket mode '%s': %w", common.EnvConfig.UnixSocketMode, err)
}
if err := os.Chmod(addr, os.FileMode(mode)); err != nil {
return nil, fmt.Errorf("failed to set UNIX socket mode '%s': %w", common.EnvConfig.UnixSocketMode, err)
}
}
// Service runner function // Service runner function
runFn := func(ctx context.Context) error { runFn := func(ctx context.Context) error {
log.Printf("Server listening on %s", addr) log.Printf("Server listening on %s", addr)

View File

@@ -33,6 +33,7 @@ type EnvConfigSchema struct {
Port string `env:"PORT"` Port string `env:"PORT"`
Host string `env:"HOST"` Host string `env:"HOST"`
UnixSocket string `env:"UNIX_SOCKET"` UnixSocket string `env:"UNIX_SOCKET"`
UnixSocketMode string `env:"UNIX_SOCKET_MODE"`
MaxMindLicenseKey string `env:"MAXMIND_LICENSE_KEY"` MaxMindLicenseKey string `env:"MAXMIND_LICENSE_KEY"`
GeoLiteDBPath string `env:"GEOLITE_DB_PATH"` GeoLiteDBPath string `env:"GEOLITE_DB_PATH"`
GeoLiteDBUrl string `env:"GEOLITE_DB_URL"` GeoLiteDBUrl string `env:"GEOLITE_DB_URL"`
@@ -53,6 +54,7 @@ var EnvConfig = &EnvConfigSchema{
Port: "1411", Port: "1411",
Host: "0.0.0.0", Host: "0.0.0.0",
UnixSocket: "", UnixSocket: "",
UnixSocketMode: "",
MaxMindLicenseKey: "", MaxMindLicenseKey: "",
GeoLiteDBPath: "data/GeoLite2-City.mmdb", GeoLiteDBPath: "data/GeoLite2-City.mmdb",
GeoLiteDBUrl: MaxMindGeoLiteCityUrl, GeoLiteDBUrl: MaxMindGeoLiteCityUrl,