diff --git a/config/config.go b/config/config.go index 7170815..b6c2b82 100644 --- a/config/config.go +++ b/config/config.go @@ -97,6 +97,8 @@ type Config struct { Addr string `toml:"addr"` + AddrUnixSocketPerm string `toml:"addr_unixsocketperm"` + HttpAddr string `toml:"http_addr"` SlaveOf string `toml:"slaveof"` diff --git a/config/config.toml b/config/config.toml index 6135848..03c1daa 100644 --- a/config/config.toml +++ b/config/config.toml @@ -3,6 +3,10 @@ # Server listen address addr = "127.0.0.1:6380" +# Unix socket permissions, 755 by default. +# Ignored for tcp socket. +addr_unixsocketperm = "0770" + # Server http listen address, set empty to disable http_addr = "127.0.0.1:11181" diff --git a/server/app.go b/server/app.go index e0e8e97..078d43d 100644 --- a/server/app.go +++ b/server/app.go @@ -3,7 +3,9 @@ package server import ( "net" "net/http" + "os" "path" + "strconv" "strings" "sync" @@ -86,10 +88,22 @@ func NewApp(cfg *config.Config) (*App, error) { return nil, err } - if app.listener, err = net.Listen(netType(cfg.Addr), cfg.Addr); err != nil { + addrNetType := netType(cfg.Addr) + + if app.listener, err = net.Listen(addrNetType, cfg.Addr); err != nil { return nil, err } + if addrNetType == "unix" && len(cfg.AddrUnixSocketPerm) > 0 { + var perm int64 + if perm, err = strconv.ParseInt(cfg.AddrUnixSocketPerm, 8, 32); err != nil { + return nil, err + } + if err = os.Chmod(cfg.Addr, os.FileMode(perm)); err != nil { + return nil, err + } + } + if len(cfg.HttpAddr) > 0 { if app.httpListener, err = net.Listen(netType(cfg.HttpAddr), cfg.HttpAddr); err != nil { return nil, err