add pid path

v4
wangyiyang 6 years ago
parent 36ff1329a7
commit e582bdf9c8
  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 = 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 {

Loading…
Cancel
Save