add pid path

v4
wangyiyang 6 years ago
parent 5c2ee50948
commit 09360ba76e
  1. 4
      conf/redis-shake.conf
  2. 9
      src/redis-shake/common/mix.go
  3. 1
      src/redis-shake/configure/configure.go
  4. 24
      src/redis-shake/main/main.go

@ -2,8 +2,10 @@
# id
id = redis-shake
# log file,日志文件,不配置将打印到stdout
# log file,日志文件,不配置将打印到stdout (e.g. /var/log/redis-shake.log )
log_file =
# pid path,进程文件存储地址,不配置将输出到项目目录下 (e.g. /var/run/ )
pid_path =
# pprof port
system_profile = 9310

@ -22,8 +22,13 @@ func WritePid(id string) (err error) {
return nil
}
func WritePidById(id string) error {
dir, _ := os.Getwd()
func WritePidById(id string, path string) error {
var dir string
if path == "" {
dir, _ = os.Getwd()
} else {
dir = path
}
pidfile := filepath.Join(dir, id) + ".pid"
if err := WritePid(pidfile); err != nil {
return err

@ -40,6 +40,7 @@ type Configuration struct {
SenderCount uint `config:"sender.count"`
SenderDelayChannelSize uint `config:"sender.delay_channel_size"`
KeepAlive uint `config:"keep_alive"`
PidPath string `config:"pid_path"`
// inner variables
ReplaceHashTag bool `config:"replace_hash_tag"`

@ -5,28 +5,28 @@
package main
import (
"encoding/json"
"flag"
"fmt"
"math"
_ "net/http/pprof"
"os"
"os/signal"
"syscall"
"runtime/debug"
"time"
"reflect"
"runtime"
"math"
_ "net/http/pprof"
"strings"
"runtime/debug"
"strconv"
"encoding/json"
"reflect"
"strings"
"syscall"
"time"
"pkg/libs/log"
"redis-shake"
"redis-shake/base"
"redis-shake/common"
"redis-shake/configure"
"redis-shake/metric"
"redis-shake"
"redis-shake/base"
"redis-shake/restful"
"pkg/libs/log"
"github.com/gugemichael/nimo4go"
logRotate "gopkg.in/natefinch/lumberjack.v2"
@ -83,7 +83,7 @@ func main() {
utils.Welcome()
utils.StartTime = fmt.Sprintf("%v", time.Now().Format(utils.GolangSecurityTime))
if err = utils.WritePidById(conf.Options.Id); err != nil {
if err = utils.WritePidById(conf.Options.Id, conf.Options.PidPath); err != nil {
crash(fmt.Sprintf("write pid failed. %v", err), -5)
}

Loading…
Cancel
Save