From 2b533e4b91562e3b97340d564298a9ac0eeb7bc1 Mon Sep 17 00:00:00 2001 From: Andy Hsu Date: Sat, 8 Jul 2023 20:17:05 +0800 Subject: [PATCH] feat: allow customize perm of unix file (close #4709) --- cmd/server.go | 11 +++++++++++ internal/conf/config.go | 15 ++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/cmd/server.go b/cmd/server.go index 1e3b218758c..461389b1ba9 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "os/signal" + "strconv" "sync" "syscall" "time" @@ -74,6 +75,16 @@ the address is defined in config file`, if err != nil { utils.Log.Fatalf("failed to listen unix: %+v", err) } + // set socket file permission + mode, err := strconv.ParseUint(conf.Conf.Scheme.UnixFilePerm, 8, 32) + if err != nil { + utils.Log.Errorf("failed to parse socket file permission: %+v", err) + } else { + err = os.Chmod(conf.Conf.Scheme.UnixFile, os.FileMode(mode)) + if err != nil { + utils.Log.Errorf("failed to chmod socket file: %+v", err) + } + } err = unixSrv.Serve(listener) if err != nil && err != http.ErrServerClosed { utils.Log.Fatalf("failed to start unix: %s", err.Error()) diff --git a/internal/conf/config.go b/internal/conf/config.go index 39838754c77..06a6973a3a2 100644 --- a/internal/conf/config.go +++ b/internal/conf/config.go @@ -20,13 +20,14 @@ type Database struct { } type Scheme struct { - Address string `json:"address" env:"ADDR"` - HttpPort int `json:"http_port" env:"HTTP_PORT"` - HttpsPort int `json:"https_port" env:"HTTPS_PORT"` - ForceHttps bool `json:"force_https" env:"FORCE_HTTPS"` - CertFile string `json:"cert_file" env:"CERT_FILE"` - KeyFile string `json:"key_file" env:"KEY_FILE"` - UnixFile string `json:"unix_file" env:"UNIX_FILE"` + Address string `json:"address" env:"ADDR"` + HttpPort int `json:"http_port" env:"HTTP_PORT"` + HttpsPort int `json:"https_port" env:"HTTPS_PORT"` + ForceHttps bool `json:"force_https" env:"FORCE_HTTPS"` + CertFile string `json:"cert_file" env:"CERT_FILE"` + KeyFile string `json:"key_file" env:"KEY_FILE"` + UnixFile string `json:"unix_file" env:"UNIX_FILE"` + UnixFilePerm string `json:"unix_file_perm" env:"UNIX_FILE_PERM"` } type LogConfig struct {