mirror of https://github.com/ledisdb/ledisdb.git
Add config param for unix socket permission (issue #203)
This commit is contained in:
parent
e6d0bae8f2
commit
316ba29713
|
@ -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"`
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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(uint32(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
|
||||
|
|
Loading…
Reference in New Issue