Merge pull request #15 from wangyiyang/develop

add pid path
v4
Vinllen Chen 6 years ago committed by GitHub
commit ecc52ea4fa
  1. 4
      conf/redis-shake.conf
  2. 9
      src/redis-shake/common/mix.go
  3. 1
      src/redis-shake/configure/configure.go
  4. 30
      src/redis-shake/main/main.go

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

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

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

@ -5,36 +5,36 @@
package main package main
import ( import (
"encoding/json"
"flag" "flag"
"fmt" "fmt"
"math"
_ "net/http/pprof"
"os" "os"
"os/signal" "os/signal"
"syscall" "reflect"
"runtime/debug"
"time"
"runtime" "runtime"
"math" "runtime/debug"
_ "net/http/pprof"
"strings"
"strconv" "strconv"
"encoding/json" "strings"
"reflect" "syscall"
"time"
"pkg/libs/log"
"redis-shake"
"redis-shake/base"
"redis-shake/common" "redis-shake/common"
"redis-shake/configure" "redis-shake/configure"
"redis-shake/metric" "redis-shake/metric"
"redis-shake"
"redis-shake/base"
"redis-shake/restful" "redis-shake/restful"
"pkg/libs/log"
"github.com/gugemichael/nimo4go" "github.com/gugemichael/nimo4go"
logRotate "gopkg.in/natefinch/lumberjack.v2" logRotate "gopkg.in/natefinch/lumberjack.v2"
) )
type Exit struct {Code int} type Exit struct{ Code int }
const( const (
TypeDecode = "decode" TypeDecode = "decode"
TypeRestore = "restore" TypeRestore = "restore"
TypeDump = "dump" TypeDump = "dump"
@ -83,7 +83,7 @@ func main() {
utils.Welcome() utils.Welcome()
utils.StartTime = fmt.Sprintf("%v", time.Now().Format(utils.GolangSecurityTime)) 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) 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 { if n, err := strconv.ParseInt(conf.Options.FakeTime[1:], 10, 64); err != nil {
return fmt.Errorf("parse fake_time failed[%v]", err) return fmt.Errorf("parse fake_time failed[%v]", err)
} else { } 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: default:
if t, err := time.Parse("2006-01-02 15:04:05", conf.Options.FakeTime); err != nil { if t, err := time.Parse("2006-01-02 15:04:05", conf.Options.FakeTime); err != nil {

Loading…
Cancel
Save