diff --git a/conf/redis-shake.conf b/conf/redis-shake.conf index 5d51c18..d3cc3cd 100644 --- a/conf/redis-shake.conf +++ b/conf/redis-shake.conf @@ -4,7 +4,8 @@ id = redis-shake # log file,日志文件,不配置将打印到stdout (e.g. /var/log/redis-shake.log ) log_file = -# pid path,进程文件存储地址,不配置将输出到项目目录下 (e.g. /var/run/ ) +# pid path,进程文件存储地址,不配置将输出到项目目录下(e.g. /var/run/), 注意这个是目录, +# 真正的pid是`{pid_path}/{id}.pid` pid_path = # pprof port diff --git a/src/redis-shake/common/mix.go b/src/redis-shake/common/mix.go index 1ad3de8..1f5c0e0 100644 --- a/src/redis-shake/common/mix.go +++ b/src/redis-shake/common/mix.go @@ -24,11 +24,22 @@ func WritePid(id string) (err error) { func WritePidById(id string, path string) error { var dir string + var err error if path == "" { - dir, _ = os.Getwd() + if dir, err = os.Getwd(); err != nil { + return err + } } else { dir = path + if _, err := os.Stat(dir); os.IsNotExist(err) { + os.Mkdir(dir, os.ModePerm) + } } + + if dir, err = filepath.Abs(dir); err != nil { + return err + } + pidfile := filepath.Join(dir, id) + ".pid" if err := WritePid(pidfile); err != nil { return err