Merge pull request #15 from wangyiyang/develop

add pid path
v4
Vinllen Chen 6 years ago committed by GitHub
commit 8f4cf32291
  1. 4
      conf/redis-shake.conf
  2. 9
      src/redis-shake/common/mix.go
  3. 1
      src/redis-shake/configure/configure.go
  4. 32
      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,36 +5,36 @@
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"
)
type Exit struct {Code int}
type Exit struct{ Code int }
const(
const (
TypeDecode = "decode"
TypeRestore = "restore"
TypeDump = "dump"
@ -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)
}
@ -240,7 +240,7 @@ func sanitizeOptions(tp string) error {
if n, err := strconv.ParseInt(conf.Options.FakeTime[1:], 10, 64); err != nil {
return fmt.Errorf("parse fake_time failed[%v]", err)
} else {
conf.Options.ShiftTime = time.Duration(n * int64(time.Millisecond) - time.Now().UnixNano())
conf.Options.ShiftTime = time.Duration(n*int64(time.Millisecond) - time.Now().UnixNano())
}
default:
if t, err := time.Parse("2006-01-02 15:04:05", conf.Options.FakeTime); err != nil {
@ -291,7 +291,7 @@ func sanitizeOptions(tp string) error {
if tp == TypeRestore || tp == TypeSync {
// get target redis version and set TargetReplace.
if conf.Options.TargetRedisVersion, err = utils.GetRedisVersion(conf.Options.TargetAddress,
conf.Options.TargetAuthType, conf.Options.TargetPasswordRaw); err != nil {
conf.Options.TargetAuthType, conf.Options.TargetPasswordRaw); err != nil {
return fmt.Errorf("get target redis version failed[%v]", err)
} else {
if strings.HasPrefix(conf.Options.TargetRedisVersion, "4.") ||

Loading…
Cancel
Save