mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-13 00:33:06 +03:00
feat: allow setting unix socket mode (#661)
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user